3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Foo { private $foo =2; } class Hydrator { public function getPrivate($obj, $attribute) { $getter = function(){return $this->$attribute;}; return \Closure::bind($getter, $obj); } } $hydrated = new Hydrator(); $obj = new Foo(); $getter = $hydrated->getPrivate($obj, 'foo'); var_dump($getter());
based on 2Z4uE
Output for 7.1.0 - 7.2.0
Notice: Undefined variable: attribute in /in/V0gKE on line 10 Notice: Undefined property: Foo::$ in /in/V0gKE on line 10 NULL
Output for 7.0.0 - 7.0.20
Notice: Undefined variable: attribute in /in/V0gKE on line 10 Fatal error: Uncaught Error: Cannot access empty property in /in/V0gKE:10 Stack trace: #0 /in/V0gKE(19): Hydrator->{closure}() #1 {main} thrown in /in/V0gKE on line 10
Process exited with code 255.
Output for 5.4.11 - 5.6.28
Notice: Undefined variable: attribute in /in/V0gKE on line 10 Fatal error: Cannot access empty property in /in/V0gKE on line 10
Process exited with code 255.
Output for 5.3.21 - 5.3.29
Fatal error: Call to undefined method Closure::bind() in /in/V0gKE on line 11
Process exited with code 255.