#37667 [Asn->Csd]: Object is not added into array returned by __get
| From: | helly@php.net | Date: | Mon, 10 Jul 2006 00:38:43 +0000 |
| Subject: | #37667 [Asn->Csd]: Object is not added into array returned by __get | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-99263@lists.php.net to get a copy of this message | ||
ID: 37667
Updated by: helly@php.net
Reported By: alexander dot netkachev at gmail dot com
-Status: Assigned
+Status: Closed
Bug Type: Class/Object related
Operating System: *
-PHP Version: 5.1.4
+PHP Version: 5.1.*
Assigned To: helly
New Comment:
This bug has been fixed in CVS.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2006-06-02 23:18:44] helly@php.net
Ok, i have aptach for this which will generate an error for this non
working write access.
------------------------------------------------------------------------
[2006-06-02 22:50:59] helly@php.net
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.
------------------------------------------------------------------------
[2006-06-02 07:27:52] alexander dot netkachev at gmail dot com
BTW, I think about it more and now I'm not sure that the actual result
should show two elements in the array.
Actually, when the array is returned from the function, it is returned
by value, not by reference. __get seems to be an exception for this -
it returns a reference to array.
E.g.
<?php
class Class1 {
var $property = array();
function getProperty() {
return $this->property;
}
}
$c = new Class1();
$d = & $c->getProperty();
$d[] = 1;
var_dump($c);
?>
shows empty array in the $c object.
------------------------------------------------------------------------
[2006-06-01 18:54:14] tony2001@php.net
Dmitry, could you plz take a look at it?
------------------------------------------------------------------------
[2006-06-01 14:05:19] alexander dot netkachev at gmail dot com
Description:
------------
The following code inserts only second object into property array.
Reproduce code:
---------------
class Class1 {
protected $property = array();
function __get($name) {
return $this->property;
}
}
class Class2 {}
$r = new Class1();
$r->Property[] = new Class2();
$r->Property[] = new Class2();
var_dump($r);
Expected result:
----------------
object(Class1)#1 (1) {
["property:protected"]=>
array(1) {
[0]=>
object(Class2)#2 (0) {
}
[0]=>
object(Class2)#3 (0) {
}
}
}
Actual result:
--------------
object(Class1)#1 (1) {
["property:protected"]=>
array(1) {
[0]=>
object(Class2)#3 (0) {
}
}
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=37667&edit=1