3v4l.org

run code in 200+ php & hhvm versions
<?php abstract class Result { private final function __construct() { } public static function success() { return new Success(); } public static function failure() { return new Failure(); } } final class Success extends Result { public static function fakeIt() { return new self(); } } final class Failure extends Result { } var_dump(Result::success()); var_dump(Result::failure()); Success::fakeIt();
based on QbJaF
Output for 7.0.0 - 7.4.0beta1
object(Success)#1 (0) { } object(Failure)#1 (0) { } Fatal error: Uncaught Error: Call to private Result::__construct() from context 'Success' in /in/5aK01:22 Stack trace: #0 /in/5aK01(34): Success::fakeIt() #1 {main} thrown in /in/5aK01 on line 22
Process exited with code 255.
Output for hhvm-3.22.0
object(Success)#1 (0) { } object(Failure)#1 (0) { } Fatal error: Uncaught Error: Call to private method Result::__construct() from context 'Success' in /in/5aK01:-1 Stack trace: #0 /in/5aK01(-1): Success::fakeIt() #1 {main}
Process exited with code 255.
Output for hhvm-3.11.1 - 3.21.3
object(Success)#1 (0) { } object(Failure)#1 (0) { } Fatal error: Uncaught Error: Call to private method Result::__construct() from context 'Success' in /in/5aK01:22 Stack trace: #0 /in/5aK01(34): Success::fakeIt() #1 {main}
Process exited with code 255.
Output for hhvm-3.10.1
object(Success)#1 (0) { } object(Failure)#1 (0) { } Fatal error: Call to private method Result::__construct() from context 'Success' in /in/5aK01 on line 22
Process exited with code 255.
Output for 5.2.6 - 5.6.40
object(Success)#1 (0) { } object(Failure)#1 (0) { } Fatal error: Call to private Result::__construct() from context 'Success' in /in/5aK01 on line 22
Process exited with code 255.
Output for 5.0.0 - 5.2.5
Fatal error: Call to private Result::__construct() from context 'Result' in /in/5aK01 on line 11
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_CLASS in /in/5aK01 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/5aK01 on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/5aK01 on line 3
Process exited with code 255.