PHP Magic methods not working

Posted by user991047 on Stack Overflow See other posts from Stack Overflow or by user991047
Published on 2011-10-22T10:34:29Z Indexed on 2012/12/10 5:04 UTC
Read the original article Hit count: 208

Filed under:

I am trying to create a registry class with magic __set and __get my class looks like

  class Registry {
      private $vars = array();

      public function __set($key, $value)
      {
          $this->vars[$key] = $value;
          dump($key, $value);
      }

      public function __get($index)
      {
          $this->vars[$index];
      }
  } 

but if i try to save some variable in registry class in gets only the $key the $value is alway NULL.

here is the sample code how I am try to call this class

$registry   = new registry; 
$registry->router = $router; 
$registry->title = "Welcome ";

© Stack Overflow or respective owner

Related posts about php