3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Foo { public function __construct() { $args = func_get_args(); switch (count($args)) { case 2: return call_user_func_array(array($this, 'constr2'), $args); //break; case 1: return call_user_func_array(array($this, 'constr1'), $args); break; } 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);
based on TKWKE
Output for 7.0.0 - 7.2.0
constr1 called constr2 called Fatal error: Uncaught Exception: invalid number of arguments in /in/eHb0e:14 Stack trace: #0 /in/eHb0e(26): Foo->__construct('a', 'b', 3) #1 {main} thrown in /in/eHb0e on line 14
Process exited with code 255.
Output for 5.3.21 - 5.6.28
constr1 called constr2 called Fatal error: Uncaught exception 'Exception' with message 'invalid number of arguments' in /in/eHb0e:14 Stack trace: #0 /in/eHb0e(26): Foo->__construct('a', 'b', 3) #1 {main} thrown in /in/eHb0e on line 14
Process exited with code 255.