php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #70772 nowdoc does not work as documented
Submitted: 2015-10-22 18:25 UTC Modified: 2015-10-22 20:16 UTC
From: teo8976 at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: teo8976 at gmail dot com
New email:
PHP Version: OS:

 

 [2015-10-22 18:25 UTC] teo8976 at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/language.types.string
---
The example regarding newdoc syntax is broken.

Test script:
---------------
<?php
$str = <<<'EOD'
Example of string
spanning multiple lines
using nowdoc syntax.
EOD;

Expected result:
----------------
Either the script should work, or it should be replaced with a working example in the docs

Actual result:
--------------
Parse error: syntax error, unexpected end of file, expecting variable (T_VARIABLE) or heredoc end (T_END_HEREDOC) or ${ (T_DOLLAR_OPEN_CURLY_BRACES) or {$ (T_CURLY_OPEN) in /in/T9Wfr on line 6


The error message varies depending on the version of PHP.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-10-22 19:06 UTC] salathe@php.net
-Status: Open +Status: Not a bug
 [2015-10-22 19:06 UTC] salathe@php.net
This error occurs when you forget to add a newline* after the closing delimiter. The newline requirement is mentioned in the Big Red Box on the documentation page linked above, in the heredoc section.

(* or the website you're using to run the code (here's looking at you 3v4l.org) helpfully strips training whitespace from the code before execution.)
 [2015-10-22 20:16 UTC] teo8976 at gmail dot com
I didn't forget to add a newline, I put several. However, I see that the problem is with 3v4l.org (which is where I was testing) which trims them.

Anyway, a more specific error message in the case of a missing newline would probably be better.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 22:00:01 2026 UTC