33 lines
528 B
Plaintext
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 */
|