closure_043.phpt 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. --TEST--
  2. Closure 043: Scope/bounding combination invariants; static closures
  3. --FILE--
  4. <?php
  5. /* Whether it's scoped or not, a static closure cannot have
  6. * a bound instance. It should also not be automatically converted
  7. * to a non-static instance when attempting to bind one */
  8. $staticUnscoped = static function () { var_dump(isset(A::$priv)); var_dump(isset($this)); };
  9. class A {
  10. private static $priv = 7;
  11. static function getStaticClosure() {
  12. return static function() { var_dump(isset(A::$priv)); var_dump(isset($this)); };
  13. }
  14. }
  15. $staticScoped = A::getStaticClosure();
  16. echo "Before binding", "\n";
  17. $staticUnscoped(); echo "\n";
  18. $staticScoped(); echo "\n";
  19. echo "After binding, null scope, no instance", "\n";
  20. $d = $staticUnscoped->bindTo(null, null); $d(); echo "\n";
  21. $d = $staticScoped->bindTo(null, null); $d(); echo "\n";
  22. echo "After binding, null scope, with instance", "\n";
  23. $d = $staticUnscoped->bindTo(new A, null);
  24. $d = $staticScoped->bindTo(new A, null);
  25. echo "After binding, with scope, no instance", "\n";
  26. $d = $staticUnscoped->bindTo(null, 'A'); $d(); echo "\n";
  27. $d = $staticScoped->bindTo(null, 'A'); $d(); echo "\n";
  28. echo "After binding, with scope, with instance", "\n";
  29. $d = $staticUnscoped->bindTo(new A, 'A');
  30. $d = $staticScoped->bindTo(new A, 'A');
  31. echo "Done.\n";
  32. ?>
  33. --EXPECTF--
  34. Before binding
  35. bool(false)
  36. bool(false)
  37. bool(true)
  38. bool(false)
  39. After binding, null scope, no instance
  40. bool(false)
  41. bool(false)
  42. bool(false)
  43. bool(false)
  44. After binding, null scope, with instance
  45. Warning: Cannot bind an instance to a static closure in %s on line %d
  46. Warning: Cannot bind an instance to a static closure in %s on line %d
  47. After binding, with scope, no instance
  48. bool(true)
  49. bool(false)
  50. bool(true)
  51. bool(false)
  52. After binding, with scope, with instance
  53. Warning: Cannot bind an instance to a static closure in %s on line %d
  54. Warning: Cannot bind an instance to a static closure in %s on line %d
  55. Done.