closure_040.phpt 784 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. --TEST--
  2. Closure 040: Rebinding closures, bad arguments
  3. --FILE--
  4. <?php
  5. class A {
  6. private $x;
  7. private static $xs = 10;
  8. public function __construct($v) {
  9. $this->x = $v;
  10. }
  11. public function getIncrementor() {
  12. return function() { return ++$this->x; };
  13. }
  14. public function getStaticIncrementor() {
  15. return static function() { return ++static::$xs; };
  16. }
  17. }
  18. $a = new A(20);
  19. $ca = $a->getIncrementor();
  20. $cas = $a->getStaticIncrementor();
  21. try {
  22. $ca->bindTo($a, array());
  23. } catch (TypeError $e) {
  24. echo $e->getMessage(), "\n";
  25. }
  26. $cas->bindTo($a, 'A');
  27. ?>
  28. --EXPECTF--
  29. Closure::bindTo(): Argument #2 ($newScope) must be of type object|string|null, array given
  30. Warning: Cannot bind an instance to a static closure in %s on line %d