I'm trying to understand what singleton is. What i have found out so far is that singleton pattern lets me create only one instance of a class.
So far no problem but when it comes to creating a singleton class in PHP i don't know how it works !
Take a look at this example:
class Foo { static function instance() { static $inst = null; if ($inst === null) { $inst = new self; } return $inst; } static function google(){ echo 'google'; } private function __construct() { } private function __clone() { } private function __wakeup() { } } I try to make 2 instances from this class:
$obj = Foo::google(); $obj2 = Foo::google(); echo $obj2; You can see that $obj and $obj2 are 2 different objects but steel this code works and no error is thrown ! I might be wrong or confused the purpose behind singleton. I have searched a lot about it here and there but nothing seems to answer my question.
Many thanks in advance