Aer/tests/singleton_test.aer
belliash 029dd9bfb4
All checks were successful
The build was successful.
Several changes made:
* Do not overload entry point
 * Automatically call Program::__construct()
 * Automatically call Program::main();
 * Fix all tests
2018-08-12 12:52:35 +02:00

33 lines
519 B
Plaintext

final class Test {
private $value;
private function __construct() {
}
/* This is singleton */
public function getInstance() {
static $instance;
if(!$instance) {
$instance = new Test();
}
return $instance;
}
public function get() {
return $this->value;
}
public function set($value = 0) {
$this->value = $value;
}
}
final class Program {
public function main() {
$testA = Test::getInstance();
$testA->set(5);
$testB = Test::getInstance();
var_dump($testB->get());
}
} /* class */