EnumTrait: fixed regex not accepting member names with 1 character

this also fixes EnumTrait accepting invalid non-numeric characters for the first character, such as @.
This commit is contained in:
PJZ9n 2022-03-20 01:47:36 +09:00 committed by GitHub
parent fdd42fd15f
commit f4f5c3128f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -70,7 +70,7 @@ trait EnumTrait{
* @throws \InvalidArgumentException
*/
private function __construct(string $enumName){
if(preg_match('/^\D[A-Za-z\d_]+$/u', $enumName, $matches) === 0){
if(preg_match('/^(?!\d)[A-Za-z\d_]+$/u', $enumName, $matches) === 0){
throw new \InvalidArgumentException("Invalid enum member name \"$enumName\", should only contain letters, numbers and underscores, and must not start with a number");
}
$this->enumName = $enumName;