Edit report at http://bugs.php.net/bug.php?id=51715&edit=1
ID: 51715 Updated by: fel...@php.net Reported by: ninzya at inbox dot lv Summary: Lambda's definition breaks references when using use() clause. -Status: Open +Status: Bogus Type: Bug Package: Scripting Engine problem Operating System: Any PHP Version: 5.3.2 New Comment: Duplicated of #50230 Previous Comments: ------------------------------------------------------------------------ [2010-05-01 13:35:20] ninzya at inbox dot lv Sorry, have forgotten that i have already filed that bug report a while ago (http://bugs.php.net/bug.php?id=50230). I use closures a lot and would like to get this bug fixed as soon as possible. ------------------------------------------------------------------------ [2010-05-01 13:30:19] ninzya at inbox dot lv If you change lambda definition from function() use( $y){}; to function() use( &$y){}; then script outputs expected result: [...]# cat test.php <?php $x =null; // reference $x $y =&$x; // focus on this (lambda def.) function() use( &$y){}; // update value of $x via reference. $y =10; // No bug, since ref. was not broken var_dump( $x); ?> [...]# php -v PHP 5.3.2 (cli) (built: Mar 4 2010 22:12:20) Copyright (c) 1997-2010 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies [...]# php test.php int(10) ------------------------------------------------------------------------ [2010-05-01 13:27:26] ninzya at inbox dot lv Description: ------------ See test script. Test script: --------------- [...]# cat test.php <?php $x =null; // reference $x $y =&$x; // focus on this (lambda def.) function() use( $y){}; // update value of $x via reference. $y =10; // oops, bug, outputs NULL since lambda def. breaks // the reference. var_dump( $x); ?> [...]# php -v PHP 5.3.2 (cli) (built: Mar 4 2010 22:12:20) Copyright (c) 1997-2010 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies [...]# php test.php NULL Expected result: ---------------- int(10) Actual result: -------------- NULL ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=51715&edit=1