Bug #73844 [Asn->Csd]: Cannot use lexical variable $variable as a parameter name inside array_walk()
| From: | aharvey@php.net | Date: | Fri, 30 Dec 2016 19:58:11 +0000 |
| Subject: | Bug #73844 [Asn->Csd]: 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-206249@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: Assigned
+Status: Closed
Type: Bug
Package: Scripting Engine problem
Operating System: Linux
PHP Version: 7.1.0
Assigned To: aharvey
Block user comment: N
Private report: N
New Comment:
Commits made; closing.
php-src: https://github.com/php/php-src/commit/eb25e1496277079423bdf2dee5aa4133c49e1f53
Docs: http://svn.php.net/viewvc?view=revision&revision=341552
Previous Comments:
------------------------------------------------------------------------
[2016-12-30 19:57:36] 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:36:43] 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 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