3v4l.org

run code in 300+ PHP versions simultaneously
<?php class RegexTranslator { const INT = '[0-9]+'; const ALPHA = '[a-zA-Z_-]+'; const ALNUM = '[a-zA-Z0-9_-]+'; public static function translate($string) { if (!is_string($string)) { throw InvalidArgumentException(); } if (!defined(__CLASS__ . "::$string")) { throw new InvalidArgumentException('No regex translation found for this string'); } else { return constant(__CLASS__ . "::$string"); } } } echo RegexTranslator::translate('int');

preferences:
73.29 ms | 402 KiB | 5 Q