Annotation of embedaddon/php/Zend/tests/closure_039.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Closure 039: Rebinding closures, change scope, same runtime type
                      3: --FILE--
                      4: <?php
                      5: 
                      6: class A {
                      7:        private $x;
                      8:        
                      9:        public function __construct($v) {
                     10:                $this->x = $v;
                     11:        }
                     12:        
                     13:        public function getIncrementor() {
                     14:                return function() { return ++$this->x; };
                     15:        }
                     16: }
                     17: class B extends A {
                     18:        private $x;
                     19:        public function __construct($v) {
                     20:                parent::__construct($v);
                     21:                $this->x = $v*2;
                     22:        }
                     23: }
                     24: 
                     25: $a = new B(-5);
                     26: $b = new B(10);
                     27: 
                     28: $ca = $a->getIncrementor();
                     29: var_dump($ca());
                     30: 
                     31: echo "Testing with scope given as object", "\n";
                     32: 
                     33: $cb = $ca->bindTo($b, $b);
                     34: $cb2 = Closure::bind($ca, $b, $b);
                     35: var_dump($cb());
                     36: var_dump($cb2());
                     37: 
                     38: echo "Testing with scope as string", "\n";
                     39: 
                     40: $cb = $ca->bindTo($b, 'B');
                     41: $cb2 = Closure::bind($ca, $b, 'B');
                     42: var_dump($cb());
                     43: var_dump($cb2());
                     44: 
                     45: $cb = $ca->bindTo($b, NULL);
                     46: var_dump($cb());
                     47: 
                     48: ?>
                     49: --EXPECTF--
                     50: int(-4)
                     51: Testing with scope given as object
                     52: int(21)
                     53: int(22)
                     54: Testing with scope as string
                     55: int(23)
                     56: int(24)
                     57: 
                     58: Fatal error: Cannot access private property B::$x in %s on line %d

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>