php.net |  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
 [2018-05-25 13:50 UTC] 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)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-05-25 13:55 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2018-05-25 13:55 UTC] requinix@php.net
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-2018 The PHP Group
All rights reserved.
Last updated: Fri Nov 16 12:01:26 2018 UTC