php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73844 Cannot use lexical variable $variable as a parameter name inside array_walk()
Submitted: 2016-12-30 17:12 UTC Modified: 2016-12-30 19:58 UTC
From: pagescene at gmail dot com Assigned: aharvey (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 7.1.0 OS: Linux
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: pagescene at gmail dot com
New email:
PHP Version: OS:

 

 [2016-12-30 17:12 UTC] pagescene at gmail dot com
Description:
------------
The following code works fine under earlier PHP versions including PHP 7.0.x, however it results in fatal error "Cannot use lexical variable $variable as a parameter name inside array_walk()" under PHP 7.1

Test script:
---------------
$value = 'b';
$checkbox_values = ['a' => 'Aaa', 'b' => 'Bbb', 'c' => 'Ccc'];

    array_walk($checkbox_values, function(&$value, $key) use($value) {
      $value = (int)(strval($key) === $value);
});

print_r($checkbox_values);

Expected result:
----------------
Array
(
    [a] => 0
    [b] => 1
    [c] => 0
)

Actual result:
--------------
Fatal error: Cannot use lexical variable $value as a parameter name in / on line 4

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-30 19:36 UTC] aharvey@php.net
-Status: Open +Status: Assigned -Package: Arrays related +Package: Scripting Engine problem -Assigned To: +Assigned To: aharvey
 [2016-12-30 19:36 UTC] aharvey@php.net
This is expected behaviour: it was introduced in https://github.com/php/php-src/commit/35662c9bd3d88924ccf4683ff5fa2c710bb2b04b, but UPGRADING wasn't updated, so it didn't make it into the migration guide.

I'll update UPGRADING and the migration guide to note the change in PHP 7.1.
 [2016-12-30 19:57 UTC] aharvey@php.net
Automatic comment from SVN on behalf of aharvey
Revision: http://svn.php.net/viewvc/?view=revision&revision=341552
Log: Document new use() behaviour in PHP 7.1.

Fixes bug #73844 (Cannot use lexical variable $variable as a parameter name
inside array_walk()).
 [2016-12-30 19:58 UTC] aharvey@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 10 19:01:34 2024 UTC