3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace App\Localization; enum Locale { case ru; case en; public static function tryFromName(string $name): ?self { $constant = self::class.'::'.$name; if (\defined($constant)) { return \constant($constant); } return null; } public static function fromName(string $name): self { return self::tryFromName($name) ?? throw new \ValueError(sprintf( '"%s" is not a valid name for enum "%s"', $name, self::class, )); } } var_dump(Locale::tryFromName('ru')); var_dump(Locale::tryFromName('fr')); var_dump(Locale::fromName('en')); var_dump(Locale::fromName('es'));
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0 - 8.5.1
enum(App\Localization\Locale::ru) NULL enum(App\Localization\Locale::en) Fatal error: Uncaught ValueError: "es" is not a valid name for enum "App\Localization\Locale" in /in/EgBB1:24 Stack trace: #0 /in/EgBB1(35): App\Localization\Locale::fromName('es') #1 {main} thrown in /in/EgBB1 on line 24
Process exited with code 255.
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.
Output for 8.0.1 - 8.0.30
Parse error: syntax error, unexpected identifier "Locale" in /in/EgBB1 on line 5
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Parse error: syntax error, unexpected 'Locale' (T_STRING) in /in/EgBB1 on line 5
Process exited with code 255.

preferences:
125.33 ms | 410 KiB | 5 Q