From:
Operating system: Debian Linux 5
PHP version: 5.3.2
Package: Scripting Engine problem
Bug Type: Bug
Bug description:a closure fails to modify a variable in the outer scope
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)
--
Edit bug report at http://bugs.php.net/bug.php?id=52165&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=52165&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=52165&r=trysnapshot53
Try a snapshot (trunk):
http://bugs.php.net/fix.php?id=52165&r=trysnapshottrunk
Fixed in SVN:
http://bugs.php.net/fix.php?id=52165&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=52165&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=52165&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=52165&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=52165&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=52165&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=52165&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=52165&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=52165&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=52165&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=52165&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=52165&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=52165&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=52165&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=52165&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=52165&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=52165&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=52165&r=mysqlcfg