Skip to content

Commit 7d4ed8a

Browse files
committed
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 phpGH-18026 Closes phpGH-18101
1 parent a28fb52 commit 7d4ed8a

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ PHP NEWS
3737
(ilutov)
3838
. Fixed bug GH-18033 (NULL-ptr dereference when using register_tick_function
3939
in destructor). (nielsdos)
40+
. Fixed bug GH-18026 (Improve "expecting token" error for ampersand). (ilutov)
4041

4142
- Curl:
4243
. Added curl_multi_get_handles(). (timwolla)

Zend/tests/gh18026.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
GH-18026: Confusing "amp" reference in parser error
3+
--FILE--
4+
<?php
5+
6+
class Demo {
7+
private (set) mixed $v1;
8+
}
9+
10+
?>
11+
--EXPECTF--
12+
Parse error: syntax error, unexpected token ")", expecting token "&" in %s on line %d

Zend/zend_language_parser.y

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,6 +1819,14 @@ static YYSIZE_T zend_yytnamerr(char *yyres, const char *yystr)
18191819
return sizeof("\"\\\"")-1;
18201820
}
18211821

1822+
/* We used "amp" as a dummy label to avoid a duplicate token literal warning. */
1823+
if (strcmp(toktype, "\"amp\"") == 0) {
1824+
if (yyres) {
1825+
yystpcpy(yyres, "token \"&\"");
1826+
}
1827+
return sizeof("token \"&\"")-1;
1828+
}
1829+
18221830
/* Strip off the outer quote marks */
18231831
if (toktype_len >= 2 && *toktype == '"') {
18241832
toktype++;

0 commit comments

Comments
 (0)