- defined: documentation ( source)
- constant: documentation ( source)
<?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');