Reputation: 315
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 ";
Upvotes: 0
Views: 435
Reputation: 605
Your __get function doesn't return a value, that's why it's always null. It should be:
return $this->vars[$index];
Upvotes: 1
Reputation: 2435
__get
methoddump
function do?Upvotes: 3