3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public function __construct() { $args = func_get_args(); switch (count($args)) { case 2: return call_user_func_array(array($this, 'constr2'), $args); case 1: return call_user_func_array(array($this, 'constr1'), $args); } throw new Exception("invalid number of arguments"); } protected function constr1($a) { print "constr1 called\n"; } protected function constr2($a, $b) { print "constr2 called\n"; } } $a = new Foo(2); $b = new Foo(2, 3); $c = new Foo("a", "b", 3);
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
constr1 called constr2 called Fatal error: Uncaught Exception: invalid number of arguments in /in/fSEc3:12 Stack trace: #0 /in/fSEc3(24): Foo->__construct('a', 'b', 3) #1 {main} thrown in /in/fSEc3 on line 12
Process exited with code 255.
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
constr1 called constr2 called Fatal error: Uncaught exception 'Exception' with message 'invalid number of arguments' in /in/fSEc3:12 Stack trace: #0 /in/fSEc3(24): Foo->__construct('a', 'b', 3) #1 {main} thrown in /in/fSEc3 on line 12
Process exited with code 255.

preferences:
158.77 ms | 402 KiB | 182 Q