|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-12-20 10:51 UTC] yubing at cernet dot edu dot cn
[2004-12-20 11:26 UTC] derick@php.net
[2004-12-20 12:44 UTC] yubing at cernet dot edu dot cn
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 24 12:00:01 2025 UTC |
Description: ------------ foreach on array containing objects without "$key =>" is not compatible with pre-versions Is that because of the porting of those code from v5.0.2 ? b2evo and xoops use many this kind of statements to fetch the database objects. Reproduce code: --------------- $a = array(); $user->name = "peter"; $user->age = "24"; $a[0] = $user; $user->name = "ice"; $user->age = "25"; $a[1] = $user; foreach ( $a as $u){ // foreach ( $a as $key => $u) works ok print $u->name.": ".$u->age."\n"; var_dump($u); } Expected result: ---------------- peter:24 ice:25 object(stdClass)(2) { ["name"]=> string(5) "peter" ["age"]=> string(2) "24" } object(stdClass)(2) { ["name"]=> string(3) "ice" ["age"]=> string(2) "25" } Actual result: -------------- NULL:NULL NULL:NULL array(2) { [0]=> object(stdClass)(2) { ["name"]=> string(5) "peter" ["age"]=> string(2) "24" } [1]=> int(0) } array(2) { [0]=> object(stdClass)(2) { ["name"]=> string(3) "ice" ["age"]=> string(2) "25" } [1]=> int(1) }