I have this class which let's me change the private data
property using the setData
method:
abstract class FooBase{
public function __set($name, $value){
$setter = 'set'.ucfirst($name);
if(method_exists($this, $setter)) return $this->$setter($value);
throw new Exception("Property {$setter} is not defined.");
}
}
class Foo extends FooBase{
static $instance;
private $data;
public static function app(){
if(!(self::$instance instanceof self)){
self::$instance = new self();
self::app()->data = array('a' => 'somedata', 'b' => 'moredata');
}
return self::$instance;
}
public function setData($newdata){
$this->data = $newdata;
}
}
So to change it I call it like:
Foo::app()->data = array('a' => 'newdata', 'b' => 'morenewdata');
I was wondering if it's possible to somehow change only one array value from $data
, like:
Foo::app()->data['a'] = 'newdata'; // <-- this doesn't work, but it's what I would like to do...