3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Filters { /** * @return array */ public function toArray() { return array_map(function ($value) { return json_encode($value); }, get_object_vars($this)); } /** * @param array $arrayOfFilters * @return Filters */ public static function fromArray($arrayOfFilters) { $instance = new self; foreach ($arrayOfFilters as $key => $value) { $instance->{$key} = $value; } return $instance; } } final class UserFilters extends Filters { /** @var array */ private $registeredAtRange; /** * @param \DateTimeInterface $start * @param \DateTimeInterface|null $end */ public function setRegisteredAtRange(\DateTimeInterface $start, \DateTimeInterface $end = null) { if (is_null($end)) { $end = new \DateTime; } $this->registeredAtRange = [ 'start' => $start->format('Y-m-d H:i:s'), 'end' => $end->format('Y-m-d H:i:s'), ]; } /** * Will return 2 date time strings or null. * * @return array|null */ public function getRegisteredAtRange() { return $this->registeredAtRange; } } $a = new UserFilters; $a->setRegisteredAtRange(new DateTime('now')); $b = $a->toArray(); var_dump($b); var_dump(UserFilters::fromArray($b));
Output for git.master, git.master_jit, rfc.property-hooks
array(0) { } object(Filters)#3 (0) { }

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:
52.74 ms | 401 KiB | 8 Q