Initial support for Closure::bind outside of repo mode
[hiphop-php.git] / hphp / test / slow / closure / bindscope.php
blob3598199390d8b796ec9d307992782b6eb604fe26
1 <?php
3 class Y {
4 public static $x = 'in Y (static)';
5 public $y = 'in Y (instance)';
8 class X {
9 public static $x = 'in X (static)';
10 public $y = 'in X (instance)';
12 public static function getS() {
13 return static function() {
14 echo "self::\$x = "; var_dump(self::$x);
15 echo "static::\$x = "; var_dump(static::$x);
19 public function get() {
20 return function() {
21 echo "\$this->y = "; var_dump($this->y);
22 echo "self::\$x = "; var_dump(self::$x);
23 echo "static::\$x = "; var_dump(static::$x);
28 echo "\$d = \$staticNS->bindto(NULL, 'Y');\n";
29 $staticNS = static function() {
30 echo "self::\$x = "; var_dump(self::$x);
31 echo "static::\$x = "; var_dump(static::$x);
33 $d = $staticNS->bindto(NULL, 'Y');
34 $res = (new ReflectionFunction($d))->getClosureScopeClass();
35 if ($res) {
36 var_dump($res->getName());
39 $d();
41 echo "=====================================================\n";
42 echo "\$d = \$staticS->bindto(NULL, 'Y');\n";
43 $staticS = X::getS();
44 $d = $staticS->bindto(NULL, 'Y');
45 $res = (new ReflectionFunction($d))->getClosureScopeClass();
46 if ($res) {
47 var_dump($res->getName());
50 $d();
52 echo "=====================================================\n";
53 echo "\$R = \$Q->bindto(new Y, 'static');\n";
55 $Q = (new X)->get();
56 $R = $Q->bindto(new Y, 'static');
57 $res = (new ReflectionFunction($R))->getClosureScopeClass();
58 if ($res) {
59 var_dump($res->getName());
61 $R();
63 echo "=====================================================\n";
64 echo "\$R = \$Q->bindto(new Y, 'X');\n";
66 $Q = (new X)->get();
67 $R = $Q->bindto(new Y, 'X');
68 $res = (new ReflectionFunction($R))->getClosureScopeClass();
69 if ($res) {
70 var_dump($res->getName());
73 $R();
75 echo "=====================================================\n";
76 echo "\$R = \$Q->bindto(new Y, 'Y');\n";
78 $Q = (new X)->get();
79 $R = $Q->bindto(new Y, 'Y');
80 $res = (new ReflectionFunction($R))->getClosureScopeClass();
81 if ($res) {
82 var_dump($res->getName());
84 $R();