3v4l.org

run code in 300+ PHP versions simultaneously
<?php enum PaymentMethods : string { case PAYPAL = 'pay with paypal'; case STRIPE = 'pay with stripe'; public static function fromName(string $method): PaymentMethods { foreach(PaymentMethods::cases() as $case) { if ($case->name === $method) { return $case; } } return null; } } $method= "PAYPAL"; var_dump(PaymentMethods::fromName($method));
Output for 8.1.28 - 8.1.33, 8.2.3 - 8.2.29, 8.3.5 - 8.3.25, 8.4.1 - 8.4.12
enum(PaymentMethods::PAYPAL)

preferences:
54.34 ms | 406 KiB | 5 Q