|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-05-01 13:27 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 07 05:00:01 2025 UTC |
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)