Aer/tests/singleton_test.aer
belliash ff73690111
Some checks reported errors
The build has failed.
Update tests to follow new syntax.
2019-03-17 19:48:52 +01:00

33 lines
528 B
Plaintext

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