Annotation of embedaddon/php/Zend/tests/closure_043.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Closure 043: Scope/bounding combination invariants; static closures
3: --FILE--
4: <?php
5: /* Whether it's scoped or not, a static closure cannot have
6: * a bound instance. It should also not be automatically converted
7: * to a non-static instance when attempting to bind one */
8:
9: $staticUnscoped = static function () { var_dump(isset(A::$priv)); var_dump(isset($this)); };
10:
11: class A {
12: private static $priv = 7;
13: static function getStaticClosure() {
14: return static function() { var_dump(isset(A::$priv)); var_dump(isset($this)); };
15: }
16: }
17:
18: $staticScoped = A::getStaticClosure();
19:
20: echo "Before binding", "\n";
21: $staticUnscoped(); echo "\n";
22: $staticScoped(); echo "\n";
23:
24: echo "After binding, null scope, no instance", "\n";
25: $d = $staticUnscoped->bindTo(null, null); $d(); echo "\n";
26: $d = $staticScoped->bindTo(null, null); $d(); echo "\n";
27:
28: echo "After binding, null scope, with instance", "\n";
29: $d = $staticUnscoped->bindTo(new A, null); $d(); echo "\n";
30: $d = $staticScoped->bindTo(new A, null); $d(); echo "\n";
31:
32: echo "After binding, with scope, no instance", "\n";
33: $d = $staticUnscoped->bindTo(null, 'A'); $d(); echo "\n";
34: $d = $staticScoped->bindTo(null, 'A'); $d(); echo "\n";
35:
36: echo "After binding, with scope, with instance", "\n";
37: $d = $staticUnscoped->bindTo(new A, 'A'); $d(); echo "\n";
38: $d = $staticScoped->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(false)
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:
59: Warning: Cannot bind an instance to a static closure in %s on line %d
60: bool(false)
61: bool(false)
62:
63:
64: Warning: Cannot bind an instance to a static closure in %s on line %d
65: bool(false)
66: bool(false)
67:
68: After binding, with scope, no instance
69: bool(true)
70: bool(false)
71:
72: bool(true)
73: bool(false)
74:
75: After binding, with scope, with instance
76:
77: Warning: Cannot bind an instance to a static closure in %s on line %d
78: bool(true)
79: bool(false)
80:
81:
82: Warning: Cannot bind an instance to a static closure in %s on line %d
83: bool(true)
84: bool(false)
85:
86: Done.
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>