xref: /PHP-8.2/Zend/tests/bug53958.phpt (revision 64351b7a)
1--TEST--
2Bug #53958 (Closures can't 'use' shared variables by value and by reference)
3--FILE--
4<?php
5// TEST 1
6$a = 1;
7$fn1 = function() use ($a) {echo "$a\n"; $a++;};
8$fn2 = function() use ($a) {echo "$a\n"; $a++;};
9$a = 5;
10$fn1(); // 1
11$fn2(); // 1
12$fn1(); // 1
13$fn2(); // 1
14
15// TEST 2
16$b = 1;
17$fn1 = function() use (&$b) {echo "$b\n"; $b++;};
18$fn2 = function() use (&$b) {echo "$b\n"; $b++;};
19$b = 5;
20$fn1(); // 5
21$fn2(); // 6
22$fn1(); // 7
23$fn2(); // 8
24
25// TEST 3
26$c = 1;
27$fn1 = function() use (&$c) {echo "$c\n"; $c++;};
28$fn2 = function() use ($c) {echo "$c\n"; $c++;};
29$c = 5;
30$fn1(); // 5
31$fn2(); // 1
32$fn1(); // 6
33$fn2(); // 1
34
35// TEST 4
36$d = 1;
37$fn1 = function() use ($d) {echo "$d\n"; $d++;};
38$fn2 = function() use (&$d) {echo "$d\n"; $d++;};
39$d = 5;
40$fn1(); // 1
41$fn2(); // 5
42$fn1(); // 1
43$fn2(); // 6
44?>
45--EXPECT--
461
471
481
491
505
516
527
538
545
551
566
571
581
595
601
616
62