3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php final class CanNotSetProperties extends RuntimeException { public function __construct() { parent::__construct("You can not set properties on Immutable objects."); } } final class ConstructorIsVisible extends RuntimeException { public function __construct() { parent::__construct("Immutable objects can not expose the constructor."); } } final class CanNotBeCloned extends RuntimeException { public function __construct() { parent::__construct("Immutable objects can not be cloned."); } } trait Immutable { final public function __set($property, $value) { throw new CanNotSetProperties; } final public function __clone() { throw new CanNotBeCloned; } final private function __construct() { } } final class Test { use Immutable; public function __construct() { echo 'hello'; } } $test = new Test; $test->__construct();
based on GDfWq
Output for 5.4.0 - 7.2.0
hellohello
Output for 5.1.0 - 5.3.29
Parse error: syntax error, unexpected T_STRING in /in/qiUJT on line 27
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_STRING in /in/qiUJT on line 27
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_CLASS in /in/qiUJT on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_CLASS in /in/qiUJT on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/qiUJT on line 3
Process exited with code 255.