Skip to content

Commit 5501a57

Browse files
committed
Avoid enum keyword BC break
1 parent 6185f32 commit 5501a57

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
Enum keyword can still be used in classes, namespaces, functions and constants
3+
--FILE--
4+
<?php
5+
6+
namespace enum {
7+
class Foo {}
8+
}
9+
10+
namespace {
11+
class enum {}
12+
13+
function enum() {
14+
return 'enum function';
15+
}
16+
17+
const enum = 'enum constant';
18+
19+
var_dump(new enum\Foo());
20+
var_dump(new enum());
21+
var_dump(enum());
22+
var_dump(enum);
23+
}
24+
25+
?>
26+
--EXPECT--
27+
object(enum\Foo)#1 (0) {
28+
}
29+
object(enum)#1 (0) {
30+
}
31+
string(13) "enum function"
32+
string(13) "enum constant"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Enum keyword can be followed by arbitrary whitespaces
3+
--FILE--
4+
<?php
5+
6+
enum A {}
7+
enum B {}
8+
enum C {}
9+
enum E {}
10+
enum
11+
F {}
12+
enum
13+
G {}
14+
15+
?>
16+
--EXPECT--

Zend/zend_language_scanner.l

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1551,7 +1551,12 @@ NEWLINE ("\r"|"\n"|"\r\n")
15511551
RETURN_TOKEN_WITH_IDENT(T_TRAIT);
15521552
}
15531553

1554-
<ST_IN_SCRIPTING>"enum" {
1554+
/*
1555+
* The enum keyword must be followed by whitespace and another identifier.
1556+
* This avoids the BC break of using enum in classes, namespaces, functions and constants.
1557+
*/
1558+
<ST_IN_SCRIPTING>"enum"{WHITESPACE}[a-zA-Z_\x80-\xff] {
1559+
yyless(4);
15551560
RETURN_TOKEN_WITH_IDENT(T_ENUM);
15561561
}
15571562

0 commit comments

Comments
 (0)