Skip to content

Commit e01e2bb

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Fix comments between -> and keyword
2 parents c21cfa1 + b368db2 commit e01e2bb

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
@@ -15,6 +15,8 @@ PHP NEWS
1515
. Fixed bug GH-14741 (Segmentation fault in Zend/zend_types.h). (nielsdos)
1616
. Fixed bug GH-14969 (Use-after-free in property coercion with __toString()).
1717
(ilutov)
18+
. Fixed bug GH-14961 (Comment between -> and keyword results in parse error).
19+
(ilutov)
1820

1921
- Dom:
2022
. 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
@@ -1597,12 +1597,6 @@ OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_
15971597
RETURN_TOKEN_WITH_STR(T_STRING, 0);
15981598
}
15991599

1600-
<ST_LOOKING_FOR_PROPERTY>{ANY_CHAR} {
1601-
yyless(0);
1602-
yy_pop_state();
1603-
goto restart;
1604-
}
1605-
16061600
<ST_IN_SCRIPTING>"::" {
16071601
RETURN_TOKEN(T_PAAMAYIM_NEKUDOTAYIM);
16081602
}
@@ -2385,7 +2379,7 @@ inline_char_handler:
23852379
}
23862380
23872381
2388-
<ST_IN_SCRIPTING>"#"|"//" {
2382+
<ST_IN_SCRIPTING,ST_LOOKING_FOR_PROPERTY>"#"|"//" {
23892383
while (YYCURSOR < YYLIMIT) {
23902384
switch (*YYCURSOR++) {
23912385
case '\r':
@@ -2409,7 +2403,7 @@ inline_char_handler:
24092403
RETURN_OR_SKIP_TOKEN(T_COMMENT);
24102404
}
24112405

2412-
<ST_IN_SCRIPTING>"/*"|"/**"{WHITESPACE} {
2406+
<ST_IN_SCRIPTING,ST_LOOKING_FOR_PROPERTY>"/*"|"/**"{WHITESPACE} {
24132407
int doc_com;
24142408

24152409
if (yyleng > 2) {
@@ -2445,6 +2439,12 @@ inline_char_handler:
24452439
RETURN_OR_SKIP_TOKEN(T_COMMENT);
24462440
}
24472441

2442+
<ST_LOOKING_FOR_PROPERTY>{ANY_CHAR} {
2443+
yyless(0);
2444+
yy_pop_state();
2445+
goto restart;
2446+
}
2447+
24482448
<ST_IN_SCRIPTING>"?>"{NEWLINE}? {
24492449
BEGIN(INITIAL);
24502450
if (yytext[yyleng-1] != '>') {

0 commit comments

Comments
 (0)