3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Test { private $a='data'; protected $b=123; public $c=true; } /** * @author Lisachenko Alexander <lisachenko.it@gmail.com> */ class Hydrator { private function getContext() { return get_object_vars($this); } public function __invoke($object) { static $hydrator = null; if (!$hydrator) { $hydrator = (new ReflectionMethod(__CLASS__, 'getContext'))->getClosure($this); } return $hydrator->bindTo($object, get_class($object))->__invoke($object); } } $test = new Test; $hydrator = new Hydrator(); $data = $hydrator($test); var_dump($data);
Output for 7.1.0
Warning: Cannot bind method Hydrator::getContext() to object of class Test in /in/BtTRD on line 26 Fatal error: Uncaught Error: Call to a member function __invoke() on null in /in/BtTRD:26 Stack trace: #0 /in/BtTRD(32): Hydrator->__invoke(Object(Test)) #1 {main} thrown in /in/BtTRD on line 26
Process exited with code 255.
Output for 7.0.0 - 7.0.14
Warning: Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure() in /in/BtTRD on line 26 Fatal error: Uncaught Error: Call to a member function __invoke() on null in /in/BtTRD:26 Stack trace: #0 /in/BtTRD(32): Hydrator->__invoke(Object(Test)) #1 {main} thrown in /in/BtTRD on line 26
Process exited with code 255.
Output for 5.4.0 - 5.6.28
array(3) { ["a"]=> string(4) "data" ["b"]=> int(123) ["c"]=> bool(true) }
Output for 5.1.0 - 5.3.29
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /in/BtTRD on line 24
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_OBJECT_OPERATOR in /in/BtTRD on line 24
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/BtTRD on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/BtTRD on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/BtTRD on line 3
Process exited with code 255.