The issue: Implementing singleton pattern
<?php
class Singleton {
private static $instance;
public static $static = 42;
public $property;
private function __construct() {
$this->property = microtime();
}
public static function getInstance() {
if (!isset(self::$instance)) {
self::$instance = new Singleton();
}
return self::$instance;
}
}
var_dump( Singleton::getInstance() );
var_dump( Singleton::getInstance() );
?>
Output
object(Singleton)#866 (1) {
["property"]=>
string(21) "0.04797200 1731639908"
}
object(Singleton)#866 (1) {
["property"]=>
string(21) "0.04797200 1731639908"
}
PHP 4 could only simulate a singleton with global variables.
Static properties may be accessed without a class instance.
<?php
var_dump( Singleton::$static );
?>
Output
int(42)