3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Item { private $cost = 100; public function getTotal($discount = 7) { return $this->cost * $discount/(100+$discount); } } class Hydrator { public function getPrivate($obj, $attribute) { $getter = function() use ($attribute) {return $this->$attribute;}; return \Closure::bind($getter, $obj, get_class($obj)); } public function setPrivate($obj, $attribute) { $setter = function($value) use ($attribute) {$this->$attribute = $value;}; return \Closure::bind($setter, $obj, get_class($obj)); } } $obj = new Item(); $hydrated = new Hydrator(); $getFoo = $hydrated->getPrivate($obj, 'cost'); $setFoo = $hydrated->setPrivate($obj, 'cost'); echo $obj->getTotal() .PHP_EOL; $setFoo(1); echo $obj->getTotal() .PHP_EOL;
Output for git.master, git.master_jit, rfc.property-hooks
6.5420560747664 0.065420560747664

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