Bug #73844 [Opn->Asn]: Cannot use lexical variable $variable as a parameter name inside array_walk()
| From: | aharvey@php.net | Date: | Fri, 30 Dec 2016 19:36:43 +0000 |
| Subject: | Bug #73844 [Opn->Asn]: Cannot use lexical variable $variable as a parameter name inside array_walk() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-206248@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73844&edit=1
ID: 73844
Updated by: aharvey@php.net
Reported by: pagescene at gmail dot com
Summary: Cannot use lexical variable $variable as a parameter
name inside array_walk()
-Status: Open
+Status: Assigned
Type: Bug
-Package: Arrays related
+Package: Scripting Engine problem
Operating System: Linux
PHP Version: 7.1.0
-Assigned To:
+Assigned To: aharvey
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2016-12-30 17:12:16] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73844&edit=1