2018-08-10 08:51:38 +02:00
|
|
|
final class Test {
|
|
|
|
private $value;
|
|
|
|
|
|
|
|
private function __construct() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is singleton */
|
|
|
|
public function getInstance() {
|
2018-09-21 00:21:15 +02:00
|
|
|
static object $instance;
|
2018-08-10 08:51:38 +02:00
|
|
|
if(!$instance) {
|
|
|
|
$instance = new Test();
|
|
|
|
}
|
|
|
|
return $instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get() {
|
|
|
|
return $this->value;
|
|
|
|
}
|
|
|
|
|
2018-09-14 21:32:08 +02:00
|
|
|
public function set(int $value = 0) {
|
2018-08-10 08:51:38 +02:00
|
|
|
$this->value = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-12 12:52:35 +02:00
|
|
|
final class Program {
|
|
|
|
public function main() {
|
2018-09-23 17:51:47 +02:00
|
|
|
object $testA = Test::getInstance();
|
2018-08-10 08:51:38 +02:00
|
|
|
$testA->set(5);
|
2018-09-23 17:51:47 +02:00
|
|
|
object $testB = Test::getInstance();
|
2018-08-10 08:51:38 +02:00
|
|
|
var_dump($testB->get());
|
|
|
|
}
|
|
|
|
} /* class */
|