3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Domain { protected $foo; protected $bar; protected $baz; public function setFoo($foo) { $this->foo = $foo; return $this; } public function getFoo() { return $this->foo; } public function setBar($bar) { $this->bar = $bar; return $this; } public function getBar() { return $this->bar; } public function setBaz($baz) { $this->baz = $baz; return $this; } public function getBaz() { return $this->baz; } } class Dto { public $foo; public $baz; } $domainObject = new Domain(); $domainObject ->setFoo('foo') ->setBar('bar') ->setBaz('baz') ; $dtoFiller = function($domainObject, $dto) { $fetcher = function($object) { $getter = function() { return get_object_vars($this); }; return $getter->bindTo($object, $object); }; $transmitter = function(\Closure $fetcher, $dto) { foreach ($fetcher() as $property => $value) { if (property_exists($dto, $property)) { $dto->$property = $value; } } return $dto; }; return $transmitter($fetcher($domainObject), $dto); }; var_dump($dtoFiller($domainObject, new Dto()));
Output for git.master, git.master_jit, rfc.property-hooks
object(Dto)#3 (2) { ["foo"]=> string(3) "foo" ["baz"]=> string(3) "baz" }

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