ReflectionFunction_getClosureUsedVariables.phpt 975 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. --TEST--
  2. ReflectionFunctionAbstract::getClosureUsedVariables
  3. --FILE--
  4. <?php
  5. $reflector = new ReflectionFunction("strlen");
  6. var_dump($reflector->getClosureUsedVariables());
  7. $function = function() {
  8. static $one = 1;
  9. };
  10. $reflector = new ReflectionFunction($function);
  11. var_dump($reflector->getClosureUsedVariables());
  12. $one = 1;
  13. $two = 2;
  14. $function = function() use ($one, $two) {
  15. static $three = 3;
  16. };
  17. $reflector = new ReflectionFunction($function);
  18. var_dump($reflector->getClosureUsedVariables());
  19. $function = fn() => $three = [$one];
  20. $reflector = new ReflectionFunction($function);
  21. var_dump($reflector->getClosureUsedVariables());
  22. $function = function() use (&$one) {
  23. static $three = 3;
  24. };
  25. $reflector = new ReflectionFunction($function);
  26. var_dump($reflector->getClosureUsedVariables());
  27. ?>
  28. --EXPECT--
  29. array(0) {
  30. }
  31. array(0) {
  32. }
  33. array(2) {
  34. ["one"]=>
  35. int(1)
  36. ["two"]=>
  37. int(2)
  38. }
  39. array(1) {
  40. ["one"]=>
  41. int(1)
  42. }
  43. array(1) {
  44. ["one"]=>
  45. &int(1)
  46. }