I am practicing the singleton pattern using several examples. My code so far:
class LimitedEditionBuggati {
private $props = array(
'speed' => 256,
'cylinders' => 18,
'color' => 'metalic silver',
'hp' => 1200,
'price' => 5000000,
'vin' => 'the one'
);
private static $instance;
private function __construct(){}
public static function instance() {
if( empty($instance) ) {
return new LimitedEditionBuggati();
}
return self::$instance;
}
public function getProperty( $property ) {
return $this->props[$property];
}
}
$myCar = LimitedEditionBuggati::instance();
How come the private static $instance
does not get printed using print_r( $GLOBALS )
?