diff --git a/NEWS b/NEWS index 5a6c6ce7bb8..3c70acdc457 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,8 @@ PHP NEWS . Fixed bug GH-14741 (Segmentation fault in Zend/zend_types.h). (nielsdos) . Fixed bug GH-14969 (Use-after-free in property coercion with __toString()). (ilutov) + . Fixed bug GH-14961 (Comment between -> and keyword results in parse error). + (ilutov) - Dom: . Fixed bug GH-14702 (DOMDocument::xinclude() crash). (nielsdos) diff --git a/Zend/tests/gh14961.phpt b/Zend/tests/gh14961.phpt new file mode 100644 index 00000000000..f066943c4ec --- /dev/null +++ b/Zend/tests/gh14961.phpt @@ -0,0 +1,26 @@ +--TEST-- +GH-14961: Comment between -> and keyword +--FILE-- +/* comment */class = 42; +var_dump($c->/** doc comment */class); +var_dump($c-> + // line comment + class); +var_dump($c-> + # hash comment + class); +var_dump($c?->/* comment */class); + +?> +--EXPECT-- +int(42) +int(42) +int(42) +int(42) diff --git a/Zend/zend_language_scanner.l b/Zend/zend_language_scanner.l index 054ed7bdc1e..545e06e58e0 100644 --- a/Zend/zend_language_scanner.l +++ b/Zend/zend_language_scanner.l @@ -1597,12 +1597,6 @@ OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_ RETURN_TOKEN_WITH_STR(T_STRING, 0); } -{ANY_CHAR} { - yyless(0); - yy_pop_state(); - goto restart; -} - "::" { RETURN_TOKEN(T_PAAMAYIM_NEKUDOTAYIM); } @@ -2385,7 +2379,7 @@ inline_char_handler: } -"#"|"//" { +"#"|"//" { while (YYCURSOR < YYLIMIT) { switch (*YYCURSOR++) { case '\r': @@ -2409,7 +2403,7 @@ inline_char_handler: RETURN_OR_SKIP_TOKEN(T_COMMENT); } -"/*"|"/**"{WHITESPACE} { +"/*"|"/**"{WHITESPACE} { int doc_com; if (yyleng > 2) { @@ -2445,6 +2439,12 @@ inline_char_handler: RETURN_OR_SKIP_TOKEN(T_COMMENT); } +{ANY_CHAR} { + yyless(0); + yy_pop_state(); + goto restart; +} + "?>"{NEWLINE}? { BEGIN(INITIAL); if (yytext[yyleng-1] != '>') {