#31581 [Asn->Csd]: Overloaded property can't be accessed with foreach
ID: 31581
Updated by: iliaa@php.net
Reported By: evert at rooftopsolutions dot nl
-Status: Assigned
+Status: Closed
Bug Type: Scripting Engine problem
Operating System: Linux 2.4.26
PHP Version: 4CVS-2005-01-19
Assigned To: stas
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:
------------------------------------------------------------------------
[2005-01-20 00:59:51] sniper@php.net
Yet another overload bug..Stas, can you look into this too?
------------------------------------------------------------------------
[2005-01-18 13:09:06] evert at rooftopsolutions dot nl
28-Feb-2004 03:45 josh at uncommonprojects dot com
One thing about __get is that if you return an array it doesn't work
directly within a foreach...
but we already figured that out :)
------------------------------------------------------------------------
[2005-01-17 21:05:35] evert at rooftopsolutions dot nl
Did you mean I should test it on the snapshot, or is it solved on the
latest snapshot?
I noticed that a commenter on http://nl3.php.net/overload
experienced
the same problem.
------------------------------------------------------------------------
[2005-01-17 08:00:10] evert at rooftopsolutions dot nl
Description:
------------
When an array is directly accessed is accessed trough an overloaded
class, it works just fine.
When you access it trough foreach, it triggers an error.
Reproduce code:
---------------
<?
class OlClass {
var $data;
function OlClass() {
$this->data = new StdClass();
$this->data->arr = Array('a','b','c');
overload('OlClass');
}
function __get($p,&$v) {
$v = $this->data->$p;
return true;
}
}
$o = new OlClass;
print_r($o->arr);
foreach($o->arr as $value) echo($value);
?>
Expected result:
----------------
Array ( [0] => a [1] => b [2] => c )
abc
Actual result:
--------------
Array ( [0] => a [1] => b [2] => c )
Warning: Invalid argument supplied for foreach() in
/home/evert/public_html/dev/sabretooth/s41/test/test4.php on line 28
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=31581&edit=1
Thread (8 messages)