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));

preferences:
24.35 ms | 404 KiB | 5 Q