#31134 [Opn->Bgs]: foreach() semantics broken between 4.3.9 and 4.3.10

From: Date: Thu, 16 Dec 2004 20:17:50 +0000
Subject: #31134 [Opn->Bgs]: foreach() semantics broken between 4.3.9 and 4.3.10
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-70397@lists.php.net to get a copy of this message
ID: 31134 Updated by: jsjohnst@php.net Reported By: jlabonsk at eportation dot com -Status: Open +Status: Bogus Bug Type: Scripting Engine problem Operating System: Linux PHP Version: 4.3.10 New Comment: Same issue as: http://bugs.php.net/bug.php?id=31108 Upgrade Zend Optimizer and it fixes it. Previous Comments: ------------------------------------------------------------------------ [2004-12-16 20:36:35] jsjohnst@php.net I can also confirm this is an issue. ------------------------------------------------------------------------ [2004-12-16 20:24:57] jlabonsk at eportation dot com Description: ------------ The foreach($array as $key) construct returns an array for $key, instead of just the key. This breaks many scripts that count on $key being a scalar (and well, the key). Reproduce code: --------------- $test = array(2, 3, 4, 5); foreach($test as $key){ print_r($key); } Expected result: ---------------- 2345 Actual result: -------------- Array ( [0] => 2 [1] => 0 ) Array ( [0] => 3 [1] => 1 ) Array ( [0] => 4 [1] => 2 ) Array ( [0] => 5 [1] => 3 ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=31134&edit=1

« previous php.bugs (#70397) next »