3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php abstract class AbstractEvent { protected $id; private $hidden; } final class Event extends AbstractEvent implements JsonSerializable { private $value; public function __construct($id, self $value = null) { $this->id = 5; $this->value = 'abc'; } public function jsonSerialize() { return get_class_vars(); } /** * @param array $data * @return self */ public static function factory(array $data) { $params = []; $constructor = new ReflectionMethod(self::class, '__construct'); foreach ($constructor->getParameters() as $parameter) { $name = $parameter->getName(); $required = !$parameter->isOptional(); echo $parameter->getClass()->name; $params[] = self::getValue($data, $name, $required); } return new self(...$params); } } $e = Event::factory([]); echo json_encode($e);
based on qR1h0
Output for 7.2.0
Notice: Trying to get property 'name' of non-object in /in/b2tIh on line 37 Fatal error: Uncaught Error: Call to undefined method Event::getValue() in /in/b2tIh:38 Stack trace: #0 /in/b2tIh(46): Event::factory(Array) #1 {main} thrown in /in/b2tIh on line 38
Process exited with code 255.
Output for 7.0.0 - 7.1.10
Notice: Trying to get property of non-object in /in/b2tIh on line 37 Fatal error: Uncaught Error: Call to undefined method Event::getValue() in /in/b2tIh:38 Stack trace: #0 /in/b2tIh(46): Event::factory(Array) #1 {main} thrown in /in/b2tIh on line 38
Process exited with code 255.
Output for 5.6.0 - 5.6.24
Notice: Trying to get property of non-object in /in/b2tIh on line 37 Fatal error: Call to undefined method Event::getValue() in /in/b2tIh on line 38
Process exited with code 255.
Output for 5.5.0 - 5.5.38
Parse error: syntax error, unexpected '.' in /in/b2tIh on line 41
Process exited with code 255.
Output for 5.4.0 - 5.4.45
Parse error: syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in /in/b2tIh on line 33
Process exited with code 255.