|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76377 foreach( $a as $a ) works fine ...
Submitted: 2018-05-25 13:50 UTC Modified: 2018-05-25 13:55 UTC
From: nicolas dot aubanel at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 7.0.30 OS: macos
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: nicolas dot aubanel at gmail dot com
New email:
PHP Version: OS:


 [2018-05-25 13:50 UTC] nicolas dot aubanel at gmail dot com
From manual page:

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) {
  string(4) "test1"

string(4) "test1"

Actual result:
array(1) {
  string(4) "test1"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-05-25 13:55 UTC]
-Status: Open +Status: Not a bug
 [2018-05-25 13:55 UTC]
That's right, the expression is not reevaluated every time the loop runs. That would create chaos for anything other than simple variables.
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 18:01:30 2019 UTC