3v4l.org

run code in 300+ PHP versions simultaneously
<?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);
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of Event::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/b2tIh on line 20 Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/b2tIh on line 37 Warning: Attempt to read property "name" on null 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.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
60.07 ms | 402 KiB | 8 Q