mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Aside from a few very specific syntax errors for which detailed exceptions are
thrown, generally PHP just emits the default error messages generated by bison on syntax
error. These messages are very uninformative; they just say "Unexpected ... at line ...".
This is most problematic with constructs which can span an arbitrary number of lines, such
as blocks of code delimited by { }, 'if' conditions delimited by ( ), and so on. If a closing
delimiter is missed, the block will run for the entire remainder of the source file (which
could be thousands of lines), and then at the end, a parse error will be thrown with the
dreaded words: "Unexpected end of file".
Therefore, track the positions of opening and closing delimiters and ensure that they match
up correctly. If any mismatch or missing delimiter is detected, immediately throw a parse
error which points the user to the offending line. This is best done in the *lexer* and not
in the parser.
Thanks to Nikita Popov and George Peter Banyard for suggesting improvements.
Fixes bug #79368.
Closes GH-5364.
16 lines
206 B
PHP
16 lines
206 B
PHP
--TEST--
|
|
eval() parse error on function with doc comment
|
|
--FILE--
|
|
<?php
|
|
|
|
eval(
|
|
<<<EOC
|
|
/** doc comment */
|
|
function f() {
|
|
EOC
|
|
);
|
|
|
|
?>
|
|
--EXPECTF--
|
|
Parse error: Unclosed '{' in %s(%d) : eval()'d code on line %d
|