Hello,
I found following code on the Internet:
<?php
class A {
protected function __construct() {
echo __CLASS__;
}
public static function getInstance() {
$s= new static();
}
}
class B extends A {
protected function __construct() {
echo __CLASS__;
}
}
class C extends B {
protected function __construct() {
echo __CLASS__;
}
}
A::getInstance();
B::getInstance();
C::getInstance();
?>
I modified it a little and it works as expected. My classes can be singleton by inheriting from first class A.
But I don't understand '$s= new static();' expression in that class. It is not how PHP manual suggests.
Can somebody explain it to me and/or provide link to the place where it come from?
Thanks in advance