bug54039.phpt 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. --TEST--
  2. Bug #54039 (use() of static variables in lambda functions can break staticness)
  3. --FILE--
  4. <?php
  5. function test_1() {
  6. static $v = 0;
  7. ++$v;
  8. echo "Outer function increments \$v to $v\n";
  9. $f = function() use($v) {
  10. echo "Inner function reckons \$v is $v\n";
  11. };
  12. return $f;
  13. }
  14. $f = test_1(); $f();
  15. $f = test_1(); $f();
  16. function test_2() {
  17. static $v = 0;
  18. $f = function() use($v) {
  19. echo "Inner function reckons \$v is $v\n";
  20. };
  21. ++$v;
  22. echo "Outer function increments \$v to $v\n";
  23. return $f;
  24. }
  25. $f = test_2(); $f();
  26. $f = test_2(); $f();
  27. function test_3() {
  28. static $v = "";
  29. $v .= 'b';
  30. echo "Outer function catenates 'b' onto \$v to give $v\n";
  31. $f = function() use($v) {
  32. echo "Inner function reckons \$v is $v\n";
  33. };
  34. $v .= 'a';
  35. echo "Outer function catenates 'a' onto \$v to give $v\n";
  36. return $f;
  37. }
  38. $f = test_3(); $f();
  39. $f = test_3(); $f();
  40. ?>
  41. --EXPECT--
  42. Outer function increments $v to 1
  43. Inner function reckons $v is 1
  44. Outer function increments $v to 2
  45. Inner function reckons $v is 2
  46. Outer function increments $v to 1
  47. Inner function reckons $v is 0
  48. Outer function increments $v to 2
  49. Inner function reckons $v is 1
  50. Outer function catenates 'b' onto $v to give b
  51. Outer function catenates 'a' onto $v to give ba
  52. Inner function reckons $v is b
  53. Outer function catenates 'b' onto $v to give bab
  54. Outer function catenates 'a' onto $v to give baba
  55. Inner function reckons $v is bab