|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #13610 heredoc: any chars (even white space) after closing ";" causes error
Submitted: 2001-10-09 06:07 UTC Modified: 2002-05-09 02:43 UTC
Avg. Score:3.5 ± 0.5
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: rprangnell at hotmail dot com Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.0.6 OS: Windows98
Private report: No CVE-ID: None
 [2001-10-09 06:07 UTC] rprangnell at hotmail dot com
Having carefully searching the bugs database and drawn a blank on this( I made sure to include 'closed' and 'bogus' entries in my search!), I would like to point out that the new 'heredoc' syntax (which is GREAT) has a little bug that could prove troublesome as it is hard to spot. The bug is that you can't put anything other than the 'return' character after the semi-colon that closes the statement. Even a single white space character after the semi-colon forces a parse error. This can be a poser, especially if the user's editor can't display non-printing characters.

Typically, this kind of thing won't work:

$query = <<< SQL
  SELECT parentID
    FROM messages
    WHERE msgID = $msgID
SQL; // Can't put a comment (or anything else) here!

I encountered the same bug with both the PWS and the Apache ISAPI module version.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-10-09 06:10 UTC]
It is expected behavior. Although I agree it is not very handy that this is not possible. Making this a feature request.

 [2001-10-09 16:27 UTC]
This behaviour is documented in the strings section, subsection heredoc. 

I agree that this is quite annoying and strange. It can be easily modified, for example to allow anything afterwards. But this could break BC (though not likely):

$bla = <<<HEREDOC
HEREDOC is great!

Other solutions would be quite arbirary (as is the current solution by the way). Most consistent would be allowing a heredoc-string at all places where a quoted string is also allowed.

 [2001-10-09 17:59 UTC]
Patch available here:
which changes behaviour to:

A heredoc is considered closed when the heredoc identifier appears directly after a newline. Remaining characters are allowed, provided they are invalid identifyer characters.


mail('', 'heredoc test', <<<TEXT
Hello Jeroen,

TEXT, 'Cc:');

And this works:
echo <<<HEREDOC

HEREDOC; // here the heredoc ends

But this doesn't:
echo <<<HEREDOC


for the same reason as this is:
echo "bla" UMENTATION;
causes a parse error.
 [2002-01-28 21:56 UTC]
Here's a quick patch which just allows text *after* the 
semicolon, and doesn't appear to affect anything else, so
BC shouldn't be a problem. told me before that
this is 'intentional', but no-one has yet explained why...

Note that this patch may not be the best solution, but it
does illustrate what I'm after.


Index: zend_language_scanner.l
RCS file: /repository/Zend/zend_language_scanner.l,v
retrieving revision 1.43
diff -u -r1.43 zend_language_scanner.l
--- zend_language_scanner.l     2002/01/06 15:21:09     1.43
+++ zend_language_scanner.l     2002/01/29 02:54:16
@@ -1256,7 +1256,7 @@
+<ST_HEREDOC>^{LABEL}(";")? {
        int label_len;
        unsigned char unput_semicolon;

 [2002-01-28 22:00 UTC]
Yeesh. Scratch that. :) The issue remains but the patch I 
just posted here indicates a seious need for supper.

 [2002-05-08 14:26 UTC] destes at ix dot netcom dot com
This would be very useful to change.  Additionally if/when this is closed, Bug #5804 is a duplicate of this.  Thanks,

 [2002-05-09 02:43 UTC]
IIRC. This has been discussed and we decided not to have this change.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Tue Feb 07 04:05:50 2023 UTC