3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Kitchen { private $yummy = 'cake'; } class Mapper { public function map(Kitchen $kitchen, array $data) { $mapper = $this; $map = function (Kitchen $kitchen, array $data) use ($mapper) { $mapper->setYummy($kitchen, $data); }; $map = Closure::bind($map, null, $kitchen); $map($kitchen, $data); } public function setYummy(Kitchen $kitchen, array $data) { $kitchen->yummy = $data['yummy']; } } $kitchen = new Kitchen; $mapper = new Mapper; $mapper->map($kitchen, ['yummy' => 'cookie']); var_dump($kitchen); /* $sweetsThief = function (Kitchen $kitchen) { return $kitchen->yummy; }; $sweetsCop = function (Kitchen $kitchen, $yummy) { $kitchen->yummy = $yummy; }; $kitchen = new Kitchen(); $sweetsThief = Closure::bind($sweetsThief, null, $kitchen); $sweetsCop = Closure::bind($sweetsCop, null, $kitchen); var_dump($sweetsThief($kitchen)); $sweetsCop($kitchen, 'lie'); var_dump($sweetsThief($kitchen)); */
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught Error: Cannot access private property Kitchen::$yummy in /in/oK89U:24 Stack trace: #0 /in/oK89U(15): Mapper->setYummy(Object(Kitchen), Array) #1 /in/oK89U(19): Kitchen::{closure}(Object(Kitchen), Array) #2 /in/oK89U(30): Mapper->map(Object(Kitchen), Array) #3 {main} thrown in /in/oK89U on line 24
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:
50.78 ms | 401 KiB | 8 Q