Fix "expecting token" error for ampersand

Currently, this is only handled for the "unexpected token" part of the
message, but not the "expected" part.

Fixes GH-18026
Closes GH-18101
This commit is contained in:
Ilija Tovilo
2025-03-17 23:01:22 +01:00
parent a28fb52719
commit 7d4ed8af03
3 changed files with 21 additions and 0 deletions

1
NEWS
View File

@ -37,6 +37,7 @@ PHP NEWS
(ilutov) (ilutov)
. Fixed bug GH-18033 (NULL-ptr dereference when using register_tick_function . Fixed bug GH-18033 (NULL-ptr dereference when using register_tick_function
in destructor). (nielsdos) in destructor). (nielsdos)
. Fixed bug GH-18026 (Improve "expecting token" error for ampersand). (ilutov)
- Curl: - Curl:
. Added curl_multi_get_handles(). (timwolla) . Added curl_multi_get_handles(). (timwolla)

12
Zend/tests/gh18026.phpt Normal file
View File

@ -0,0 +1,12 @@
--TEST--
GH-18026: Confusing "amp" reference in parser error
--FILE--
<?php
class Demo {
private (set) mixed $v1;
}
?>
--EXPECTF--
Parse error: syntax error, unexpected token ")", expecting token "&" in %s on line %d

View File

@ -1819,6 +1819,14 @@ static YYSIZE_T zend_yytnamerr(char *yyres, const char *yystr)
return sizeof("\"\\\"")-1; return sizeof("\"\\\"")-1;
} }
/* We used "amp" as a dummy label to avoid a duplicate token literal warning. */
if (strcmp(toktype, "\"amp\"") == 0) {
if (yyres) {
yystpcpy(yyres, "token \"&\"");
}
return sizeof("token \"&\"")-1;
}
/* Strip off the outer quote marks */ /* Strip off the outer quote marks */
if (toktype_len >= 2 && *toktype == '"') { if (toktype_len >= 2 && *toktype == '"') {
toktype++; toktype++;