Initial support for Closure::bind outside of repo mode
[hiphop-php.git] / hphp / test / zend / good / Zend / tests / closure_044.php
blob134b673df241843542c6019f0896ee8d01d6c77e
1 <?php
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)); };
7 class A {
8 private static $priv = 7;
9 function getClosure() {
10 return function() { var_dump(isset(A::$priv)); var_dump(isset($this)); };
14 $a = new A();
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";
37 echo "Done.\n";