3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class AbstractClass { public function __construct() { echo 'aaa'; } // Our abstract method only needs to define the required arguments abstract protected function prefixName($name); } class ConcreteClass extends AbstractClass { public function __construct($a) { echo $a; } // Our child class may define optional arguments not in the parent's signature public function prefixName($name, $separator=0 ) { if ($name == "Pacman") { $prefix = "Mr"; } elseif ($name == "Pacwoman") { $prefix = "Mrs"; } else { $prefix = ""; } return "{$prefix}{$separator} {$name}"; } } $class = new ConcreteClass; echo $class->prefixName("Pacman"), "\n"; echo $class->prefixName("Pacwoman"), "\n"; ?>
Output for 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 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
Fatal error: Uncaught ArgumentCountError: Too few arguments to function ConcreteClass::__construct(), 0 passed in /in/F6l60 on line 31 and exactly 1 expected in /in/F6l60:14 Stack trace: #0 /in/F6l60(31): ConcreteClass->__construct() #1 {main} thrown in /in/F6l60 on line 14
Process exited with code 255.
Output for 5.5.0 - 5.5.35, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20
Warning: Missing argument 1 for ConcreteClass::__construct(), called in /in/F6l60 on line 31 and defined in /in/F6l60 on line 14 Notice: Undefined variable: a in /in/F6l60 on line 15 Mr0 Pacman Mrs0 Pacwoman
Output for 5.2.3 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45
Warning: Missing argument 1 for ConcreteClass::__construct(), called in /in/F6l60 on line 31 and defined in /in/F6l60 on line 14 Mr0 Pacman Mrs0 Pacwoman
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.2
<br /> <b>Warning</b>: Missing argument 1 for ConcreteClass::__construct(), called in /in/F6l60 on line 31 and defined in <b>/in/F6l60</b> on line <b>14</b><br /> Mr0 Pacman Mrs0 Pacwoman
Output for 5.0.0 - 5.0.5
<br /> <b>Warning</b>: Missing argument 1 for ConcreteClass::__construct() in <b>/in/F6l60</b> on line <b>14</b><br /> Mr0 Pacman Mrs0 Pacwoman
Output for 4.4.2 - 4.4.9
<br /> <b>Parse error</b>: syntax error, unexpected T_CLASS in <b>/in/F6l60</b> on line <b>2</b><br />
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
<br /> <b>Parse error</b>: parse error, unexpected T_CLASS in <b>/in/F6l60</b> on line <b>2</b><br />
Process exited with code 255.
Output for 4.3.2 - 4.3.4
<br /> <b>Parse error</b>: parse error in <b>/in/F6l60</b> on line <b>2</b><br />
Process exited with code 255.

preferences:
297.59 ms | 401 KiB | 361 Q