2018-08-10 08:51:38 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-12 12:52:35 +02:00
|
|
|
final class Program {
|
|
|
|
public function main() {
|
2018-08-10 08:51:38 +02:00
|
|
|
$testA = Test::getInstance();
|
|
|
|
$testA->set(5);
|
|
|
|
$testB = Test::getInstance();
|
|
|
|
var_dump($testB->get());
|
|
|
|
}
|
|
|
|
} /* class */
|