3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php trait Immutable { public function __construct() { //DO shit } public function __set($name, $value) { throw new Exception("can't touch this, nah nah nuh nahhh"); } public function __get($name) { return $this->$name; } } class ImmutableThingy { use Immutable; protected $foo = 'bar'; public function __construct() { // What the fuck ever broh } } $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
object(ImmutableThingy)#1 (1) { ["foo":protected]=> string(3) "bar" } string(3) "bar" Fatal error: Uncaught Exception: can't touch this, nah nah nuh nahhh in /in/Zrb3S:10 Stack trace: #0 /in/Zrb3S(33): ImmutableThingy->__set('foo', 'baz') #1 {main} thrown in /in/Zrb3S on line 10
Process exited with code 255.
Output for 5.4.11 - 5.6.28
object(ImmutableThingy)#1 (1) { ["foo":protected]=> string(3) "bar" } string(3) "bar" Fatal error: Uncaught exception 'Exception' with message 'can't touch this, nah nah nuh nahhh' in /in/Zrb3S:10 Stack trace: #0 /in/Zrb3S(33): ImmutableThingy->__set('foo', 'baz') #1 {main} thrown in /in/Zrb3S on line 10
Process exited with code 255.
Output for 5.3.21 - 5.3.29
Parse error: syntax error, unexpected T_STRING in /in/Zrb3S on line 3
Process exited with code 255.