#39725 [Opn->Fbk]: PHP raising notice when reading an overloaded property

From: Date: Mon, 04 Dec 2006 10:54:37 +0000
Subject: #39725 [Opn->Fbk]: PHP raising notice when reading an overloaded property
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-105853@lists.php.net to get a copy of this message
ID: 39725 Updated by: tony2001@php.net Reported By: denis at edistar dot com -Status: Open +Status: Feedback Bug Type: Scripting Engine problem Operating System: Linux PHP Version: 5.2.0 New Comment: Expected behaviour. For detailed explanation please in the existing reports regarding foreach(). Previous Comments: ------------------------------------------------------------------------ [2006-12-04 09:58:43] 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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=39725&edit=1

« previous php.bugs (#105853) next »