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

1.1       misho       1: --TEST--
                      2: Closure 044: Scope/bounding combination invariants; non static closures
                      3: --FILE--
                      4: <?php
                      5: /* A non-static closure has a bound instance if it has a scope
                      6:  * and does't have an instance if it has no scope */
                      7: 
                      8: $nonstaticUnscoped = function () { var_dump(isset(A::$priv)); var_dump(isset($this)); };
                      9: 
                     10: class A {
                     11:        private static $priv = 7;
                     12:        function getClosure() {
                     13:                return function() { var_dump(isset(A::$priv)); var_dump(isset($this)); };
                     14:        }
                     15: }
                     16: 
                     17: $a = new A();
                     18: $nonstaticScoped = $a->getClosure();
                     19: 
                     20: echo "Before binding", "\n";
                     21: $nonstaticUnscoped(); echo "\n";
                     22: $nonstaticScoped(); echo "\n";
                     23: 
                     24: echo "After binding, null scope, no instance", "\n";
                     25: $d = $nonstaticUnscoped->bindTo(null, null); $d(); echo "\n";
                     26: $d = $nonstaticScoped->bindTo(null, null); $d(); echo "\n";
                     27: 
                     28: echo "After binding, null scope, with instance", "\n";
                     29: $d = $nonstaticUnscoped->bindTo(new A, null); $d(); echo "\n";
                     30: $d = $nonstaticScoped->bindTo(new A, null); $d(); echo "\n";
                     31: 
                     32: echo "After binding, with scope, no instance", "\n";
                     33: $d = $nonstaticUnscoped->bindTo(null, 'A'); $d(); echo "\n";
                     34: $d = $nonstaticScoped->bindTo(null, 'A'); $d(); echo "\n";
                     35: 
                     36: echo "After binding, with scope, with instance", "\n";
                     37: $d = $nonstaticUnscoped->bindTo(new A, 'A'); $d(); echo "\n";
                     38: $d = $nonstaticScoped->bindTo(new A, 'A'); $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, null scope, no instance
                     51: bool(false)
                     52: bool(false)
                     53: 
                     54: bool(false)
                     55: bool(false)
                     56: 
                     57: After binding, null scope, with instance
                     58: bool(false)
                     59: bool(true)
                     60: 
                     61: bool(false)
                     62: bool(true)
                     63: 
                     64: After binding, with scope, no instance
                     65: bool(true)
                     66: bool(false)
                     67: 
                     68: bool(true)
                     69: bool(false)
                     70: 
                     71: After binding, with scope, with instance
                     72: bool(true)
                     73: bool(true)
                     74: 
                     75: bool(true)
                     76: bool(true)
                     77: 
                     78: Done.

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