closure_062.phpt 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. --TEST--
  2. Closure $this unbinding deprecation
  3. --FILE--
  4. <?php
  5. class Test {
  6. public function method() {
  7. echo "instance scoped, non-static, \$this used\n";
  8. $fn = function() {
  9. var_dump($this);
  10. };
  11. $fn->bindTo(null);
  12. echo "instance scoped, static, \$this used\n";
  13. $fn = static function() {
  14. var_dump($this);
  15. };
  16. $fn->bindTo(null);
  17. echo "instance scoped, non-static, \$this not used\n";
  18. $fn = function() {
  19. var_dump($notThis);
  20. };
  21. $fn->bindTo(null);
  22. }
  23. public static function staticMethod() {
  24. echo "static scoped, non-static, \$this used\n";
  25. $fn = function() {
  26. var_dump($this);
  27. };
  28. $fn->bindTo(null);
  29. echo "static scoped, static, \$this used\n";
  30. $fn = static function() {
  31. var_dump($this);
  32. };
  33. $fn->bindTo(null);
  34. echo "static scoped, static, \$this not used\n";
  35. $fn = function() {
  36. var_dump($notThis);
  37. };
  38. $fn->bindTo(null);
  39. }
  40. }
  41. (new Test)->method();
  42. Test::staticMethod();
  43. ?>
  44. --EXPECTF--
  45. instance scoped, non-static, $this used
  46. Warning: Cannot unbind $this of closure using $this in %s on line %d
  47. instance scoped, static, $this used
  48. instance scoped, non-static, $this not used
  49. static scoped, non-static, $this used
  50. static scoped, static, $this used
  51. static scoped, static, $this not used