|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37667 Object is not added into array returned by __get
Submitted: 2006-06-01 14:05 UTC Modified: 2006-07-10 00:38 UTC
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: alexander dot netkachev at gmail dot com Assigned: helly (profile)
Status: Closed Package: Class/Object related
PHP Version: 5.1.* OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: alexander dot netkachev at gmail dot com
New email:
PHP Version: OS:


 [2006-06-01 14:05 UTC] alexander dot netkachev at gmail dot com
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();

Expected result:
object(Class1)#1 (1) {
  array(1) {
    object(Class2)#2 (0) {
    object(Class2)#3 (0) {

Actual result:
object(Class1)#1 (1) {
  array(1) {
    object(Class2)#3 (0) {


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-06-01 18:54 UTC]
Dmitry, could you plz take a look at it?
 [2006-06-02 07:27 UTC] 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.


class Class1 {
	var $property = array();
	function getProperty() {
		return $this->property;

$c = new Class1();
$d = & $c->getProperty();
$d[] = 1;


shows empty array in the $c object.
 [2006-06-02 22:50 UTC]
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 23:18 UTC]
Ok, i have aptach for this which will generate an error for this non working write access.
 [2006-07-10 00:38 UTC]
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
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Sep 25 16:03:37 2021 UTC