3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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 $self::$attribute;}; return \Closure::bind($getter, $obj, get_class($obj)); } public function setPrivate($obj, $attribute) { $setter = function($value) use ($attribute) {$self::$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;
based on 5OGnc
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Error: Undefined class constant 'cost' in /in/BZ8Ai:7 Stack trace: #0 /in/BZ8Ai(30): Item->getTotal() #1 {main} thrown in /in/BZ8Ai on line 7
Process exited with code 255.
Output for 5.4.11 - 5.6.28
Fatal error: Undefined class constant 'cost' in /in/BZ8Ai on line 7
Process exited with code 255.
Output for 5.3.21 - 5.3.29
Fatal error: Call to undefined method Closure::bind() in /in/BZ8Ai on line 15
Process exited with code 255.