php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #40283 Heredoc syntax documentation incorrect?
Submitted: 2007-01-30 09:25 UTC Modified: 2007-02-04 13:36 UTC
From: hugorumens at yahoo dot com Assigned: bjori (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: WinXP
Private report: No CVE-ID: None
 [2007-01-30 09:25 UTC] hugorumens at yahoo dot com
Description:
------------
Regarding this page: http://uk.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

The first sentence reads:

"Another way to delimit strings is by using heredoc syntax ("<<<"). One should provide an identifier after <<<, then the string, and then the same identifier to close the quotation."

Surely this should read, for example:

"...One should provide an identifier after <<<, followed by a newline character, then the string..."

The same situation as described for the closing identifier is needed for the opening, that of a newline char, else a
parse error occurs. This is not clear in the docs as is.

Secondly:

Are the references to "except possibly a semicolon (;)" correct? A semicolon is absolutely needed after the closing identifier to avoid a parse error.

Thanks.



Reproduce code:
---------------
<?php

$somevar = <<<ABC
This is my string that HAS to start on this newline.
If the word 'This' was on the same line as the ABC
identifier, I'd get a parse error.
The semicolon after my closing identifier is absolutely
needed.
ABC;
?>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-01-30 09:59 UTC] rquadling@php.net
The ; is NOT absolutely necessary. Here is a contrived example of when not ...

<?php
$s_Text = <<<END_TEXT
This is a line of text.

END_TEXT
. <<<MORE_TEXT
This is more text.

MORE_TEXT;

echo $s_Text;
?>

Produced output of ...

This is a line of text.
This is more text.


The only criteria is that the closing tag must be left aligned.
 [2007-02-04 13:36 UTC] bjori@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Nov 26 04:00:02 2025 UTC