3v4l.org

run code in 300+ PHP versions simultaneously
<?php class foo { public function printItem($string) { echo 'Foo: ' . $string . PHP_EOL; } public function printPHP() { echo 'PHP is great.' . PHP_EOL; } } class bar extends foo { public function printItem($string) { echo 'Bar: ' . $string . PHP_EOL; echo __CLASS__; } } $foo = new foo(); $bar = new bar(); $foo->printItem('baz'); // Output: 'Foo: baz' $foo->printPHP(); // Output: 'PHP is great' $bar->printItem('baz'); // Output: 'Bar: baz' $bar->printPHP(); // Output: 'PHP is great' ?><?php class foo { public function printItem($string) { echo 'Foo: ' . $string . PHP_EOL; } public function printPHP() { echo 'PHP is great.' . PHP_EOL; } } class bar extends foo { public function printItem($string) { echo 'Bar: ' . $string . PHP_EOL; echo __CLASS__; } } $foo = new foo(); $bar = new bar(); $foo->printItem('baz'); // Output: 'Foo: baz' $foo->printPHP(); // Output: 'PHP is great' $bar->printItem('baz'); // Output: 'Bar: baz' $bar->printPHP(); // Output: 'PHP is great' ?>
Output for 7.4.3 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Foo: baz PHP is great. Bar: baz barPHP is great. Fatal error: Cannot declare class foo, because the name is already in use in /in/TiqTi on line 33
Process exited with code 255.
Output for 7.2.29 - 7.2.33, 7.3.16 - 7.3.33
Fatal error: Cannot declare class bar, because the name is already in use in /in/TiqTi on line 53
Process exited with code 255.
Output for 5.3.0 - 5.3.27, 5.4.0 - 5.4.19
Fatal error: Cannot redeclare class bar in /in/TiqTi on line 53
Process exited with code 255.

preferences:
139.6 ms | 401 KiB | 184 Q