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: call_user_func_array(array($this, 'constr2'), $args); break; case 1: 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 3GlJp
Output for 7.0.0 - 7.2.0
constr1 called Fatal error: Uncaught Exception: invalid number of arguments in /in/TKWKE:14 Stack trace: #0 /in/TKWKE(24): Foo->__construct(2) #1 {main} thrown in /in/TKWKE on line 14
Process exited with code 255.
Output for 5.3.21 - 5.6.28
constr1 called Fatal error: Uncaught exception 'Exception' with message 'invalid number of arguments' in /in/TKWKE:14 Stack trace: #0 /in/TKWKE(24): Foo->__construct(2) #1 {main} thrown in /in/TKWKE on line 14
Process exited with code 255.