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 git.master_jit, git.master, rfc.property-hooks
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.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
64.49 ms | 406 KiB | 5 Q