Lets say I have these classes:
class Foo {
public $_data;
public function addObject($obj) {
$this->_data['objects'][] = $obj;
}
}
class Bar {
public $_data;
public function __construct() {
$this->_data['value'] = 42;
}
public function setValue($value) {
$this->_data['value'] = $value;
}
}
$foo = new Foo();
$bar = new Bar();
$foo->addObject($bar);
foreach($foo->_data['objects'] as $object) {
$object->setValue(1);
}
echo $foo->_data['objects'][0]->_data['value']; //42
My actual code is this, very similar, uses ArrayAccess:
foreach($this->_data['columns'] as &$column) {
$filters = &$column->getFilters();
foreach($filters as &$filter) {
$filter->filterCollection($this->_data['collection']);
}
}
filterCollection changes a value in $filter, but when you look at the $this object, the value is not right.
$object. It's not the one you are outputing later ($foo->_data['objects'][0]).publickeywords, if you ran this in PHP 5 it would work as you expect. I tested your code and I got 1.clone $object, and even then it does only a shallow copy.