1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| class Test
{
protected $_foo = array("conditions" => "ALL", "criteria" => null );
protected $_bar = array();
public function setProperty($property, $key, $value)
{
if('_' !== substr($property, 0, 1))
{
$property = "_{$property}";
}
if(array_key_exists($key, $this->$property))
{
$this->{$property}[$key] = $value; //ne fonctionne pas
$this->_foo[$key] = $value; //fonctionne
}
else
{
throw new Exception("Undefined properties".$property);
}
}
}
$test = new Test();
$test->setProperty("_foo","criteria","blablabla");
var_dump($test); |