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(Failure::success()); Success::fakeIt();
based on MciOL
Output for 7.1.25 - 7.4.0beta1
object(Success)#1 (0) { } object(Success)#1 (0) { } Fatal error: Uncaught Error: Call to private Result::__construct() from context 'Success' in /in/QbJaF:22 Stack trace: #0 /in/QbJaF(34): Success::fakeIt() #1 {main} thrown in /in/QbJaF on line 22
Process exited with code 255.