Bug #76377 [Opn->Nab]: foreach( $a as $a ) works fine ...

From: Date: Fri, 25 May 2018 13:55:36 +0000
Subject: Bug #76377 [Opn->Nab]: foreach( $a as $a ) works fine ...
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-215370@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76377&edit=1 ID: 76377 Updated by: requinix@php.net Reported by: nicolas dot aubanel at gmail dot com Summary: foreach( $a as $a ) works fine ... -Status: Open +Status: Not a bug Type: Bug Package: *General Issues Operating System: macos PHP Version: 7.0.30 Block user comment: N Private report: N New Comment: That's right, the expression is not reevaluated every time the loop runs. That would create chaos for anything other than simple variables. Previous Comments: ------------------------------------------------------------------------ [2018-05-25 13:50:32] nicolas dot aubanel at gmail dot com Description: ------------ --- From manual page: http://www.php.net/control-structures.foreach --- array expression is not reevaluated on each loop Test script: --------------- $a = array(1 => array("test1"), 2, 3, 17); foreach ($a as $a) { var_dump( $a ); } Expected result: ---------------- array(1) { [0]=> string(4) "test1" } string(4) "test1" Actual result: -------------- array(1) { [0]=> string(4) "test1" } int(2) int(3) int(17) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=76377&edit=1

« previous php.bugs (#215370) next »