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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 03:01:32 2024 UTC