3v4l.org

run code in 300+ PHP versions simultaneously
<?php final class DemoFile { public function getError(int $code) : ?string { $error = null; $error = match ($code) { 10 => 'code_10', 11 => 'code_11', }; return $error; } } $demo = new DemoFile(); var_dump($demo->getError(10)); var_dump($demo->getError(11)); var_dump($demo->getError(12));
Output for 8.1.23 - 8.1.29, 8.2.10 - 8.2.23, 8.3.0 - 8.3.4, 8.3.6 - 8.3.11
string(7) "code_10" string(7) "code_11" Fatal error: Uncaught UnhandledMatchError: Unhandled match case 12 in /in/E64Um:9 Stack trace: #0 /in/E64Um(21): DemoFile->getError(12) #1 {main} thrown in /in/E64Um on line 9
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 string(7) "code_10" string(7) "code_11" Fatal error: Uncaught UnhandledMatchError: Unhandled match case 12 in /in/E64Um:9 Stack trace: #0 /in/E64Um(21): DemoFile->getError(12) #1 {main} thrown in /in/E64Um on line 9
Process exited with code 255.
Output for 8.0.0 - 8.0.3
string(7) "code_10" string(7) "code_11" Fatal error: Uncaught UnhandledMatchError: Unhandled match value of type int in /in/E64Um:9 Stack trace: #0 /in/E64Um(21): DemoFile->getError(12) #1 {main} thrown in /in/E64Um on line 9
Process exited with code 255.
Output for 7.3.0 - 7.3.27, 7.4.0 - 7.4.16
Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW) in /in/E64Um on line 10
Process exited with code 255.

preferences:
64.13 ms | 410 KiB | 5 Q