#20814 [Opn->Ver]: reproducable, freaky parse error in 'here document' structure
| From: | sniper@php.net | Date: | Sun, 08 Dec 2002 17:17:49 +0000 |
| Subject: | #20814 [Opn->Ver]: reproducable, freaky parse error in 'here document' structure | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-27071@lists.php.net to get a copy of this message | ||
ID: 20814
Updated by: sniper@php.net
Reported By: kumar@chicagomodular.com
-Status: Open
+Status: Verified
Bug Type: Scripting Engine problem
Operating System: all
PHP Version: 4.4.0-dev
Previous Comments:
------------------------------------------------------------------------
[2002-12-04 14:58:11] msopacua@php.net
To clarify the line mismatch:
AFAIK it's the same as a missing '}' in if/else. It will report on the
__last__ expected '}', while the error will intuitively start on the
__first__ unclosed '}'.
The '$' is 'end' as in regexps.
------------------------------------------------------------------------
[2002-12-04 11:24:55] philip@php.net
To clarify a few points:
a) This is known and is both documented and is a current feature
request:
http://bugs.php.net/bug.php?id=8685
http://www.php.net/language.types.string#language.types.string.syntax.heredoc
b) The error that's reported is odd, and looks something like this:
Parse error: parse error, unexpected $ in test.php on line 42
Where 42 is, for example, on the last line of test.php even when the
error is elsewhere. This error sorta makes sense in most cases (like a
missing quote or closing brace) but IMHO not here. Maybe someone can
briefly explain what PHP is thinking.
c) Many have attempted to fix this and many more have reported it (a)
but it appears to be almost impossible to fix and remains a feature
request. Again, it is documented with a big fat warning.
Am leaving as open as this mentions the strange error too (b), not just
the known feature request.
------------------------------------------------------------------------
[2002-12-04 11:23:05] kumar@chicagomodular.com
[quick on the trigger]... scratch that last sentence ... I
was going to point out that the closing tag has to be flush
left but I think that is not a bug.
------------------------------------------------------------------------
[2002-12-04 11:04:39] kumar@chicagomodular.com
I've tested this on PHP 4.2.3 for OSX, Open BSD, Linux...
If you leave any whitespace after the closing tag of a here
document structure (not sure if that's what it is called,
like in Perl) a parse error will occur but never for the
correct line. This seems like a bug to me because a semi-
colon should terminate the code allowing the programmer to
put comments or whatever after the semi-colon.
Here is an example:
$variable = "variable";
$someVariable = <<<hereDocument
<html>
<body>
<b>text text $variable
testing here document</b>
</body>
</html>
hereDocument; // closing comment or just whitespace
echo $someVariable;
After the closing "hereDocument;" if you leave any
whitespace (other than a carriage return) or text, a parse
error is generated but the line number never leads you to
the right place. This can be very confusing if you are
working on a large class (like I was) and you left a tab or
space after a closing tag. I'm not sure how consciously
supported the here document structure is but this is worth
addressing since here documents can be very useful for
storing large variables containing HTML code with double
and single quotes, for example. While I'm submitting this
bug, I might as well point
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=20814&edit=1