Hello internals,
Bug #37667 describes a problem with returning an array from __get()
in write context.
<?php
class Class1 {
var $property = array();
function getProperty() {
return $this->property;
}
}
$c = new Class1();
$d = & $c->getProperty();
$d[] = 1;
var_dump($c);
?>
The engine sees the read to the array property as a write no matter
whether it is a read or write operation. I think we should pass the
correct mode and then in the get_property handler use the info to
protect against writing to a returned array since reading it is pretty
fine of course. Right now we use the access type only to silence
warnings in case of BP_VAR_IS. No further distincion is done using
the access type. So i patched the necessary changes into my HEAD and
also verified that the patch does not affect any test case. So it
seems quite good. But i do not want to decide here since it is a) a
change of behavior and b) it introduces a new error message.
Now with the patch applied the above code will result in the following
error message:
Fatal error: Cannot use array returned from Test::__get('property') in write context in %sbug37667.php on line %d
Comments?
Best regards,
Marcus