# Fix for bug #37667

- Thread: https://externals.io/message/23872
- Original archive: https://news-web.php.net/php.internals/23872
- Started by Marcus Boerger on 2006-06-02T23:28:30+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #23872 — Marcus Boerger — 2006-06-02T23:28:30+00:00

URL: https://externals.io/message/23872#23872

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
