php-src/Zend/tests/closure_004.phpt

36 lines
433 B
Plaintext
Raw Normal View History

2008-07-08 15:05:04 +08:00
--TEST--
Closure 004: Lambda with lexical variables (scope lifetime)
--FILE--
<?php
function run () {
2020-02-04 05:52:20 +08:00
$x = 4;
2008-07-08 15:05:04 +08:00
2020-02-04 05:52:20 +08:00
$lambda1 = function () use ($x) {
echo "$x\n";
};
2008-07-08 15:05:04 +08:00
2020-02-04 05:52:20 +08:00
$lambda2 = function () use (&$x) {
echo "$x\n";
$x++;
};
2008-07-08 15:05:04 +08:00
2020-02-04 05:52:20 +08:00
return array($lambda1, $lambda2);
2008-07-08 15:05:04 +08:00
}
list ($lambda1, $lambda2) = run();
$lambda1();
$lambda2();
$lambda1();
$lambda2();
echo "Done\n";
?>
--EXPECT--
4
4
4
5
Done