3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Item { private static $cost = 100; public function getTotal($discount = 7) { return self::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 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught Error: Undefined constant Item::cost in /in/5OGnc:7 Stack trace: #0 /in/5OGnc(30): Item->getTotal() #1 {main} thrown in /in/5OGnc on line 7
Process exited with code 255.
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Fatal error: Uncaught Error: Undefined class constant 'cost' in /in/5OGnc:7 Stack trace: #0 /in/5OGnc(30): Item->getTotal() #1 {main} thrown in /in/5OGnc on line 7
Process exited with code 255.
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.38
Fatal error: Undefined class constant 'cost' in /in/5OGnc on line 7
Process exited with code 255.

preferences:
215.15 ms | 402 KiB | 322 Q