php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39725 PHP raising notice when reading an overloaded property
Submitted: 2006-12-04 09:58 UTC Modified: 2006-12-04 11:21 UTC
From: denis at edistar dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.0 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: denis at edistar dot com
New email:
PHP Version: OS:

 

 [2006-12-04 09:58 UTC] denis at edistar dot com
Description:
------------
Php 5.2 raises a notice when i try to read an overloaded 
property using foreach construct.

The foreach works correctly, so I don't think the warning 
should be raised.
Otherwise the foreach should not work (as don't work reset, 
next, current and other array functions).

Thank you,
Denis


Reproduce code:
---------------
class a {

    private $myArr;

    public function __construct() {
        $this->myArr = array('1','2','3','4');
    }

    public function __get($p) {
         if($p == 'myArr') {
             return $this->myArr;
         }
    }

}

$myObj = new a();

foreach($myObj->myArr as $value) {
    echo "myValue: " . $value."\n";
}



Expected result:
----------------
myValue: 1
myValue: 2
myValue: 3
myValue: 4




Actual result:
--------------
Notice: Indirect modification of overloaded property a::
$myArr has no effect in /tmp/test.php on line 21
myValue: 1
myValue: 2
myValue: 3
myValue: 4


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-12-04 10:54 UTC] tony2001@php.net
Expected behaviour. For detailed explanation please in the existing reports regarding foreach().
 [2006-12-04 10:54 UTC] tony2001@php.net
.
 [2006-12-04 11:21 UTC] denis at edistar dot com
Could you specify exactly which report for the foreach 
construct you are referring?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 13:01:27 2024 UTC