3v4l.org

run code in 300+ PHP versions simultaneously
<?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 { } final class Fake extends Result { function Fake() {echo 'wtf';} } var_dump(Result::success()); var_dump(Result::failure()); var_dump(new Fake());
Output for 8.1.23 - 8.1.34, 8.2.10 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
object(Success)#1 (0) { } object(Failure)#1 (0) { } Fatal error: Uncaught Error: Call to private Result::__construct() from global scope in /in/HdA1u:40 Stack trace: #0 {main} thrown in /in/HdA1u on line 40
Process exited with code 255.
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.30, 7.2.0 - 7.2.20, 7.3.0 - 7.3.7
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Fake has a deprecated constructor in /in/HdA1u on line 30 Fatal error: Cannot override final Result::__construct() with Fake::Fake() in /in/HdA1u on line 33
Process exited with code 255.
Output for 5.1.2 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Fatal error: Cannot override final Result::__construct() with Fake::Fake() in /in/HdA1u on line 33
Process exited with code 255.
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.1
Fatal error: Call to private Result::__construct() from context 'Result' in /in/HdA1u 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/HdA1u on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_CLASS in /in/HdA1u on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/HdA1u on line 3
Process exited with code 255.

preferences:
84.46 ms | 2163 KiB | 4 Q