Skip to content

Commit d44cf9b

Browse files
committed
Replace "unexpected character" warning with ParseError
Closes GH-4767.
1 parent 11d1396 commit d44cf9b

File tree

5 files changed

+7
-22
lines changed

5 files changed

+7
-22
lines changed

UPGRADING

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ PHP 8.0 UPGRADE NOTES
109109
* Attempting to read an out-of-bounds string offset.
110110

111111
RFC: https://wiki.php.net/rfc/engine_warnings
112+
. Unexpected characters in source files (such as null bytes outside of
113+
strings) will now result in a ParseError exception instead of a compile
114+
warning.
112115

113116
- COM:
114117
. Removed the ability to import case-insensitive constants from type

Zend/tests/warning_during_heredoc_scan_ahead.phpt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,12 @@ No warnings should be thrown during heredoc scan-ahead
44
<?php
55

66
<<<TEST
7-
${x}
87
\400
98
${/*}
109
TEST;
1110

1211
?>
1312
--EXPECTF--
14-
Warning: Unexpected character in input: '' (ASCII=1) state=0 in %s on line %d
15-
1613
Warning: Octal escape sequence overflow \400 is greater than \377 in %s on line %d
1714

1815
Warning: Unterminated comment starting line %d in %s on line %d

Zend/zend_language_scanner.l

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2834,14 +2834,7 @@ nowdoc_scan_done:
28342834
RETURN_TOKEN(END);
28352835
}
28362836
2837-
if (!SCNG(heredoc_scan_ahead)) {
2838-
zend_error(E_COMPILE_WARNING, "Unexpected character in input: '%c' (ASCII=%d) state=%d", yytext[0], yytext[0], YYSTATE);
2839-
}
2840-
if (PARSER_MODE()) {
2841-
goto restart;
2842-
} else {
2843-
RETURN_TOKEN(T_BAD_CHARACTER);
2844-
}
2837+
RETURN_TOKEN(T_BAD_CHARACTER);
28452838
}
28462839
28472840
*/

ext/tokenizer/tests/bad_character.phpt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,21 @@ foreach ($codes as $code) {
1919
echo $token, "\n";
2020
}
2121
}
22+
echo "\n";
2223
}
2324

2425
?>
25-
--EXPECTF--
26-
Warning: Unexpected character in input: ' in %s on line %d
26+
--EXPECT--
2727
T_OPEN_TAG 6
2828
T_BAD_CHARACTER 1
2929
T_WHITESPACE 1
3030
T_STRING 3
3131

32-
Warning: Unexpected character in input: '%s' (ASCII=1) state=0 in %s on line %d
3332
T_OPEN_TAG 6
3433
T_BAD_CHARACTER 1
3534
T_WHITESPACE 1
3635
T_STRING 3
3736

38-
Warning: Unexpected character in input: '%s' (ASCII=1) state=0 in %s on line %d
39-
40-
Warning: Unexpected character in input: '%s' (ASCII=2) state=0 in %s on line %d
41-
42-
Warning: Unexpected character in input: '%s' (ASCII=3) state=0 in %s on line %d
4337
T_OPEN_TAG 6
4438
T_BAD_CHARACTER 1
4539
T_BAD_CHARACTER 1

tests/lang/bug71897.phpt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,4 @@ eval("
1010

1111
?>
1212
--EXPECTF--
13-
Warning: Unexpected character in input: '%s' (ASCII=127) state=0 in %s(%d) : eval()'d code on line %d
14-
15-
Parse error: syntax error, unexpected 'b' (T_STRING) in %s(%d) : eval()'d code on line %d
13+
Parse error: syntax error, unexpected '%s' (T_BAD_CHARACTER) in %s on line %d

0 commit comments

Comments
 (0)