#45126 [Ver->Asn]: Can not pass userdata by reference to array_walk_recursive()

From: Date: Fri, 21 Nov 2008 17:24:13 +0000
Subject: #45126 [Ver->Asn]: Can not pass userdata by reference to array_walk_recursive()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-131182@lists.php.net to get a copy of this message
ID: 45126 Updated by: jani@php.net Reported By: mark at dynom dot nl -Status: Verified +Status: Assigned Bug Type: Arrays related Operating System: * PHP Version: 5CVS, 6CVS (2008-11-21) -Assigned To: +Assigned To: tony2001 New Comment: Seems to be related: bug #39576 (odd that the report talks about array_intersect though?) Tony, can you check this out? Previous Comments: ------------------------------------------------------------------------ [2008-11-21 17:10:50] jani@php.net Note: I fixed the typo in summary, this is about array_walk_recursive() (and propably array_walk() has same issue) ------------------------------------------------------------------------ [2008-05-29 10:55:26] mark at dynom dot nl Description: ------------ Only old-style call pass by reference works with array_merge_recursive, but the 'new' way doesn't Reproduce code: --------------- <?php $ar = array('a'=>array(1,5,9,12=>array(1,3,5,200)), 1,3,100, 100=>array(1,9,50)); //--- ONE ------------------------------------ $result_one = array(); array_walk_recursive($ar, 'walker_one', $result_one); function walker_one($v, $k, &$result) { $result[ $v ] = $v; } //--- TWO ------------------------------------ $result_two = array(); array_walk_recursive($ar, 'walker_two', &$result_two); function walker_two($v, $k, $result) { $result[ $v ] = $v; } var_dump($result_one, $result_two); Expected result: ---------------- array(7) { [1]=> int(1) [5]=> int(5) [9]=> int(9) [3]=> int(3) [200]=> int(200) [100]=> int(100) [50]=> int(50) } array(7) { [1]=> int(1) [5]=> int(5) [9]=> int(9) [3]=> int(3) [200]=> int(200) [100]=> int(100) [50]=> int(50) } Actual result: -------------- array(0) { } array(7) { [1]=> int(1) [5]=> int(5) [9]=> int(9) [3]=> int(3) [200]=> int(200) [100]=> int(100) [50]=> int(50) } ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=45126&edit=1

« previous php.bugs (#131182) next »