php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52165 a closure fails to modify a variable in the outer scope
Submitted: 2010-06-23 22:32 UTC Modified: 2011-11-15 15:59 UTC
From: TerenceHardwicke at safetymail dot info Assigned: felipe (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3.2 OS: Debian Linux 5
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: TerenceHardwicke at safetymail dot info
New email:
PHP Version: OS:

 

 [2010-06-23 22:32 UTC] TerenceHardwicke at safetymail dot info
Description:
------------
my configure line was:

./configure  --prefix /usr/local/php/5.3.2 --disable-libxml --disable-dom --disable-simplexml --disable-xml --disable-xmlreader --disable-xmlwriter --without-pear

Test script:
---------------
<?php
$total = 0;
f(function ($x) use (&$total) { $total += $x; }, function () use ($total) {});
var_dump($total);

$total = 0;
f(function ($x) use (&$total) { $total += $x; });
var_dump($total);

function f($g) {
  foreach (range(1, 10) as $x)
    $g($x);
}


Expected result:
----------------
The following 2 lines should be output by the script:

int(55)
int(55)

Actual result:
--------------
The script outputs the following 2 lines:

int(0)
int(55)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-11-15 15:59 UTC] felipe@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: felipe
 [2011-11-15 15:59 UTC] felipe@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.

It has already been fixed. Thanks.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 21:01:33 2024 UTC