Hi, I'm just starting my journey into OOP - and I'm currently trying to roll my own MVC - purely for learning purposes. I'm working through a tutorial in the Apress PHP-Objects Patterns Practice book. I've created a registry singleton object using the private __construct/__clone technique:
class Registry
{
private static $instance;
private $values = array();
private function __construct(){}
private function __clone(){}
public static function getInstance(){
if( !isset( self::$instance ) ){
self::$instance = new Registry();
}
return self::$instance;
}
public function get( $key ) {
if ( isset( $this->values[$key] ) ) {
return $this->values[$key];
}
return null;
}
public function set( $key, $val ) {
$this->values[$key] = $val;
}
}
I get an instance of this object directly i.e:
Registry::getInstance();
However, (following the syntax in the tutorial) - if I try and access the public methods using the '->' method - e.g:
Registry->setVal('page',$page);
I get a parse error. I can only access the methods using the scope resolution operator - i.e '::'.
I'm assuming this is because the object wrapper has not been instantiated - but I just want to verify/discuss this issue with y'all...