3v4l.org

run code in 300+ PHP versions simultaneously
<?php class User { private $id; private $username; } class MySqlUserMapper { public function fetchByUsername($username) { $row = array( 'id' => '1', 'username' => $username, ); $user = new User; $this->hydrate($user, $row); return $user; } private function hydrate(User $user, array $row) { static $hydrator; if (!$hydrator) { $hydrator = function (array $row) { var_dump($this); foreach ($row as $k => $v) { $this->{$k} = $v; } }; } $hydrator = $hydrator->bindTo($user, $user); $hydrator($row); } } $mapper = new MySqlUserMapper(); var_dump($mapper->fetchByUsername('mabe'));
Output for git.master, git.master_jit, rfc.property-hooks
object(User)#2 (2) { ["id":"User":private]=> NULL ["username":"User":private]=> NULL } object(User)#2 (2) { ["id":"User":private]=> string(1) "1" ["username":"User":private]=> string(4) "mabe" }

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.4 ms | 401 KiB | 8 Q