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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 14:04:04 2025 UTC