php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51715 Lambda's definition breaks references when using use() clause.
Submitted: 2010-05-01 13:27 UTC Modified: 2010-05-01 23:54 UTC
From: ninzya at inbox dot lv Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.2 OS: Any
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ninzya at inbox dot lv
New email:
PHP Version: OS:

 

 [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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-01 13:30 UTC] 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:35 UTC] 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 23:54 UTC] felipe@php.net
-Status: Open +Status: Bogus
 [2010-05-01 23:54 UTC] felipe@php.net
Duplicated of #50230
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Aug 07 14:00:03 2025 UTC