3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait Immutable { final public function __construct() { //DO shit var_dump("In trait constructor"); } 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() { var_dump("In class constructor"); // What the fuck ever broh } } $thing = new ImmutableThingy; var_dump($thing, $thing->foo); $thing->foo = 'baz'; var_dump($thing, $thing->foo);

preferences:
30.24 ms | 402 KiB | 5 Q