You have not declared $var in your class which is why it cannot be found as referenced.
Try the following -
<?php
class MyClass {
private $vars;
public function __construct(Array $properties=array()){
$this->vars = $properties;
}
public function __set($property, $value){
return $this->vars[$property] = $value;
}
public function __get($property){
return array_key_exists($property, $this->vars)
? $this->vars[$property]
: null
;
}
}
?>
Usage will be the same -
$foo = new MyClass(array("hello" => "world"));
$foo->hello;
$foo->invader = "Codeignite";
$foo->invader;
$foo->invalid;