#31194 [Opn]: foreach without "$key =>" is not compatible with pre-versions

From: Date: Mon, 20 Dec 2004 09:51:13 +0000
Subject: #31194 [Opn]: foreach without "$key =>" is not compatible with pre-versions
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-70671@lists.php.net to get a copy of this message
ID: 31194 User updated by: yubing at cernet dot edu dot cn Reported By: yubing at cernet dot edu dot cn Status: Open Bug Type: Scripting Engine problem Operating System: Redhat Linux 8.0 PHP Version: 4.3.10 New Comment: faint, maybe it's because of the problem of ZendOptmizer. Previous Comments: ------------------------------------------------------------------------ [2004-12-20 10:41:00] yubing at cernet dot edu dot cn 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) } ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=31194&edit=1

« previous php.bugs (#70671) next »