php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42235 Overloaded properties not allowing modification
Submitted: 2007-08-07 16:27 UTC Modified: 2007-08-16 11:57 UTC
Votes:2
Avg. Score:4.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: stephen dot cuppett at webmastersinc dot net Assigned: dmitry (profile)
Status: Not a bug Package: Class/Object related
PHP Version: 5.2.4RC1 OS: *
Private report: No CVE-ID: None
 [2007-08-07 16:27 UTC] stephen dot cuppett at webmastersinc dot net
Description:
------------
Also documented in: http://pear.php.net/bugs/bug.php?id=11775

There appears to be a regression as to Bug #39449:
http://bugs.php.net/bug.php?id=39449

On 5.2.4RC1, I'm getting the immutable overloaded properties problem with DB_DataObject and in the simple test below.

Also bugs:
   41116, 40828, 40823, 39990

Reproduce code:
---------------
<?php
    class MyObj {
        private $map;
        public function __construct() {
            $this->map = array();
        }
        public function __set($vn, $value) {
            $this->map[$vn] = $value;
        }
        public function __get($vn) {
            return $this->map[$vn];
        }
    }
    $myvar = new MyObj();
    $myvar->test_var = array();
    $myvar->test_var['tester'] = 3;
    $myvar->test_var['tester2'] = 5;
    
    var_dump($myvar->test_var);
?>

Expected result:
----------------
C:\temp\dataobject_test>php simpletest.php
array(2) {
  ["tester"]=>
  int(3)
  ["tester2"]=>
  int(5)
}

Actual result:
--------------
C:\temp\dataobject_test>php simpletest.php
PHP Notice:  Indirect modification of overloaded property MyObj::$test_var has no effect in C:\temp\dataobject_test\simpletest.php on line 16

Notice: Indirect modification of overloaded property MyObj::$test_var has no effect in C:\temp\dataobject_test\simpletest.php on line 16
PHP Notice:  Indirect modification of overloaded property MyObj::$test_var has no effect in C:\temp\dataobject_test\simpletest.php on line 17

Notice: Indirect modification of overloaded property MyObj::$test_var has no effect in C:\temp\dataobject_test\simpletest.php on line 17
array(0) {
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-07 16:35 UTC] stephen dot cuppett at webmastersinc dot net
It should be noted that the supposed congruent case works:

<?php
    class MyObj {
        public $test_var;
    }
    $myvar = new MyObj();
    $myvar->test_var = array();
    $myvar->test_var['tester'] = 3;
    $myvar->test_var['tester2'] = 5;
    
    var_dump($myvar->test_var);    
?>

C:\temp\dataobject_test>php simpletest.php
array(2) {
  ["tester"]=>
  int(3)
  ["tester2"]=>
  int(5)
}
 [2007-08-11 11:57 UTC] jani@php.net
Dmitry, check this out please.
 [2007-08-16 11:57 UTC] dmitry@php.net
Indirect modification is not allowed because you return value from __get() by value. You should see corresponding warnings.

To get that you like you should just return from get by reference.

public function &__get($vn) {
    return $this->map[$vn];
}

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 12:01:27 2024 UTC