2 /* A non-static closure has a bound instance if it has a scope
3 * and doesn't have an instance if it has no scope */
5 $nonstaticUnscoped = function () { var_dump(isset(A
::$priv)); var_dump(isset($this)); };
8 private static $priv = 7;
9 function getClosure() {
10 return function() { var_dump(isset(A
::$priv)); var_dump(isset($this)); };
15 $nonstaticScoped = $a->getClosure();
17 echo "Before binding", "\n";
18 $nonstaticUnscoped(); echo "\n";
19 $nonstaticScoped(); echo "\n";
21 echo "After binding, null scope, no instance", "\n";
22 $d = $nonstaticUnscoped->bindTo(null, null); $d(); echo "\n";
23 $d = $nonstaticScoped->bindTo(null, null); $d(); echo "\n";
25 echo "After binding, null scope, with instance", "\n";
26 $d = $nonstaticUnscoped->bindTo(new A
, null); $d(); echo "\n";
27 $d = $nonstaticScoped->bindTo(new A
, null); $d(); echo "\n";
29 echo "After binding, with scope, no instance", "\n";
30 $d = $nonstaticUnscoped->bindTo(null, 'A'); $d(); echo "\n";
31 $d = $nonstaticScoped->bindTo(null, 'A'); $d(); echo "\n";
33 echo "After binding, with scope, with instance", "\n";
34 $d = $nonstaticUnscoped->bindTo(new A
, 'A'); $d(); echo "\n";
35 $d = $nonstaticScoped->bindTo(new A
, 'A'); $d(); echo "\n";