xref: /PHP-8.0/Zend/tests/closure_004.phpt (revision f8d79582)
1--TEST--
2Closure 004: Lambda with lexical variables (scope lifetime)
3--FILE--
4<?php
5
6function run () {
7    $x = 4;
8
9    $lambda1 = function () use ($x) {
10        echo "$x\n";
11    };
12
13    $lambda2 = function () use (&$x) {
14        echo "$x\n";
15        $x++;
16    };
17
18    return array($lambda1, $lambda2);
19}
20
21list ($lambda1, $lambda2) = run();
22
23$lambda1();
24$lambda2();
25$lambda1();
26$lambda2();
27
28echo "Done\n";
29?>
30--EXPECT--
314
324
334
345
35Done
36