Bug #51715 [Opn]: Lambda's definition breaks references when using use() clause.

From: Date: Sat, 01 May 2010 11:35:21 +0000
Subject: Bug #51715 [Opn]: Lambda's definition breaks references when using use() clause.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-150079@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=51715&edit=1

 ID:               51715
 User updated by:  ninzya at inbox dot lv
 Reported by:      ninzya at inbox dot lv
 Summary:          Lambda's definition breaks references when using use()
                   clause.
 Status:           Open
 Type:             Bug
 Package:          Scripting Engine problem
 Operating System: Any
 PHP Version:      5.3.2

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[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


Thread (4 messages)

« previous php.bugs (#150079) next »