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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 08 07:01:29 2025 UTC