ArrayObject doesn't go along with array_map, array_reduce, and similar functions that expect a real array as an input. If you want an array property of an object to be copied by reference, wrap it with any kind of object:
class Test
{
private $array;
public function __construct()
{
$this->array = (object) ['array' => []];
}
// we also need to return it by reference
public function &getMyArray()
{
return $this->array->array;
}
}
Sample usage:
$test = new Test();
$test->getMyArray()[] = 'Hello';
$another = clone $test;
$another->getMyArray()[] = 'Fucking';
$third = clone $another;
$third->getMyArray()[] = 'World!';
unset($test->getMyArray()[1]);
var_dump($test->getMyArray() === $third->getMyArray());
var_dump(implode(" ", $test->getMyArray()));
var_dump(gettype($test->getMyArray()));
Sample output:
bool(true)
string(12) "Hello World!"
string(5) "array"