Bug #66031 [Opn->Nab]: use() problem with array_walk[_recursive]
| From: | johannes@php.net | Date: | Mon, 04 Nov 2013 14:27:38 +0000 |
| Subject: | Bug #66031 [Opn->Nab]: use() problem with array_walk[_recursive] | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-182588@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66031&edit=1
ID: 66031
Updated by: johannes@php.net
Reported by: bugzilla77 at gmail dot com
Summary: use() problem with array_walk[_recursive]
-Status: Open
+Status: Not a bug
Type: Bug
Package: Scripting Engine problem
Operating System: Win 7 64
PHP Version: 5.5.6RC1
Block user comment: N
Private report: N
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
You are passing the bound variable by value, not by reference. Try "use (&$c)" else
$c++ will increment on a copy. Same for the other example with $r.
Previous Comments:
------------------------------------------------------------------------
[2013-11-04 13:57:04] bugzilla77 at gmail dot com
Description:
------------
use() do not work with array_walk[_recursive]
Test script:
---------------
<?php
$a=['a'=>'p','b'=>['c'=>'a','d'=>'s'],'e'=>'s'];
$c=0;array_walk($a,function()use($c){$c++;});
$r='';array_walk_recursive($a,function($v)use($r){$r.=$v;});
print($c.'/'.$r); // 3/pass
?>
Expected result:
----------------
3/pass
Actual result:
--------------
0/
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66031&edit=1