Aer Interpreter Source
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

37 lines
645 B

final class Test {
private int $value;
private void __construct() {
print('Constructor called.' + "\n");
}
private void __destruct() {
print('Destructor called.' + "\n");
}
/* This is singleton */
public static 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 */