3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php trait Immutable { public function __set($name, $value) { throw new Exception("can't touch this, nah nah nuh nahhh"); } } class ImmutableThingy { use Immutable; protected $foo = 'bar'; } $thing = new ImmutableThingy; var_dump($thing, $thing->foo); $thing->foo = 'baz'; var_dump($thing, $thing->foo);
based on NO5s6
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Error: Cannot access protected property ImmutableThingy::$foo in /in/nhNUN:17 Stack trace: #0 {main} thrown in /in/nhNUN on line 17
Process exited with code 255.
Output for 5.4.11 - 5.6.28
Fatal error: Cannot access protected property ImmutableThingy::$foo in /in/nhNUN on line 17
Process exited with code 255.
Output for 5.3.21 - 5.3.29
Parse error: syntax error, unexpected T_STRING in /in/nhNUN on line 3
Process exited with code 255.