Skip to content

Commit b368db2

Browse files
committed
Fix comments between -> and keyword
Comments should not fall out of ST_LOOKING_FOR_PROPERTY. Fixes GH-14961 Closes GH-14976
1 parent e07813a commit b368db2

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ PHP NEWS
1414
. Fixed bug GH-14741 (Segmentation fault in Zend/zend_types.h). (nielsdos)
1515
. Fixed bug GH-14969 (Use-after-free in property coercion with __toString()).
1616
(ilutov)
17+
. Fixed bug GH-14961 (Comment between -> and keyword results in parse error).
18+
(ilutov)
1719

1820
- Dom:
1921
. Fixed bug GH-14702 (DOMDocument::xinclude() crash). (nielsdos)

Zend/tests/gh14961.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
GH-14961: Comment between -> and keyword
3+
--FILE--
4+
<?php
5+
6+
class C {
7+
public $class = C::class;
8+
}
9+
10+
$c = new C();
11+
$c->/* comment */class = 42;
12+
var_dump($c->/** doc comment */class);
13+
var_dump($c->
14+
// line comment
15+
class);
16+
var_dump($c->
17+
# hash comment
18+
class);
19+
var_dump($c?->/* comment */class);
20+
21+
?>
22+
--EXPECT--
23+
int(42)
24+
int(42)
25+
int(42)
26+
int(42)

Zend/zend_language_scanner.l

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,12 +1587,6 @@ NEWLINE ("\r"|"\n"|"\r\n")
15871587
RETURN_TOKEN_WITH_STR(T_STRING, 0);
15881588
}
15891589

1590-
<ST_LOOKING_FOR_PROPERTY>{ANY_CHAR} {
1591-
yyless(0);
1592-
yy_pop_state();
1593-
goto restart;
1594-
}
1595-
15961590
<ST_IN_SCRIPTING>"::" {
15971591
RETURN_TOKEN(T_PAAMAYIM_NEKUDOTAYIM);
15981592
}
@@ -2375,7 +2369,7 @@ inline_char_handler:
23752369
}
23762370
23772371
2378-
<ST_IN_SCRIPTING>"#"|"//" {
2372+
<ST_IN_SCRIPTING,ST_LOOKING_FOR_PROPERTY>"#"|"//" {
23792373
while (YYCURSOR < YYLIMIT) {
23802374
switch (*YYCURSOR++) {
23812375
case '\r':
@@ -2399,7 +2393,7 @@ inline_char_handler:
23992393
RETURN_OR_SKIP_TOKEN(T_COMMENT);
24002394
}
24012395

2402-
<ST_IN_SCRIPTING>"/*"|"/**"{WHITESPACE} {
2396+
<ST_IN_SCRIPTING,ST_LOOKING_FOR_PROPERTY>"/*"|"/**"{WHITESPACE} {
24032397
int doc_com;
24042398

24052399
if (yyleng > 2) {
@@ -2435,6 +2429,12 @@ inline_char_handler:
24352429
RETURN_OR_SKIP_TOKEN(T_COMMENT);
24362430
}
24372431

2432+
<ST_LOOKING_FOR_PROPERTY>{ANY_CHAR} {
2433+
yyless(0);
2434+
yy_pop_state();
2435+
goto restart;
2436+
}
2437+
24382438
<ST_IN_SCRIPTING>"?>"{NEWLINE}? {
24392439
BEGIN(INITIAL);
24402440
if (yytext[yyleng-1] != '>') {

0 commit comments

Comments
 (0)