Annotation of embedaddon/php/Zend/tests/closure_046.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: Closure 046: Rebinding: preservation of previous scope when "static" given as scope arg (same as closure #041)
        !             3: --FILE--
        !             4: <?php
        !             5: 
        !             6: /* It's impossible to preserve the previous scope when doing so would break
        !             7:  * the invariants that, for non-static closures, having a scope is equivalent
        !             8:  * to having a bound instance. */
        !             9: 
        !            10: $nonstaticUnscoped = function () { var_dump(isset(A::$priv)); var_dump(isset($this)); };
        !            11: 
        !            12: class A {
        !            13:        private static $priv = 7;
        !            14:        function getClosure() {
        !            15:                return function() { var_dump(isset(A::$priv)); var_dump(isset($this)); };
        !            16:        }
        !            17: }
        !            18: class B extends A {}
        !            19: 
        !            20: $a = new A();
        !            21: $nonstaticScoped = $a->getClosure();
        !            22: 
        !            23: echo "Before binding", "\n";
        !            24: $nonstaticUnscoped(); echo "\n";
        !            25: $nonstaticScoped(); echo "\n";
        !            26: 
        !            27: echo "After binding, no instance", "\n";
        !            28: $d = $nonstaticUnscoped->bindTo(null, "static"); $d(); echo "\n";
        !            29: $d = $nonstaticScoped->bindTo(null, "static"); $d(); echo "\n";
        !            30: //$d should have been turned to static
        !            31: $d->bindTo($d);
        !            32: 
        !            33: echo "After binding, with same-class instance for the bound one", "\n";
        !            34: $d = $nonstaticUnscoped->bindTo(new A, "static"); $d(); echo "\n";
        !            35: $d = $nonstaticScoped->bindTo(new A, "static"); $d(); echo "\n";
        !            36: 
        !            37: echo "After binding, with different instance for the bound one", "\n";
        !            38: $d = $nonstaticScoped->bindTo(new B, "static"); $d(); echo "\n";
        !            39: 
        !            40: echo "Done.\n";
        !            41: 
        !            42: --EXPECTF--
        !            43: Before binding
        !            44: bool(false)
        !            45: bool(false)
        !            46: 
        !            47: bool(true)
        !            48: bool(true)
        !            49: 
        !            50: After binding, no instance
        !            51: bool(false)
        !            52: bool(false)
        !            53: 
        !            54: bool(true)
        !            55: bool(false)
        !            56: 
        !            57: 
        !            58: Warning: Cannot bind an instance to a static closure in %s on line %d
        !            59: After binding, with same-class instance for the bound one
        !            60: bool(false)
        !            61: bool(true)
        !            62: 
        !            63: bool(true)
        !            64: bool(true)
        !            65: 
        !            66: After binding, with different instance for the bound one
        !            67: bool(true)
        !            68: bool(true)
        !            69: 
        !            70: Done.

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