Bug->Doc #76608 [Ver]: Heredoc end label should not require an additional trailing character

[email protected]
Newsgroups php.doc.bugs
Message-ID <[email protected]>
Edit report at https://bugs.php.net/bug.php?id=76608&edit=1

 ID:                 76608
 Updated by:         [email protected]
 Reported by:        mattacosta at gmail dot com
 Summary:            Heredoc end label should not require an additional
                     trailing character
 Status:             Verified
-Type:               Bug
+Type:               Documentation Problem
 Package:            Scripting Engine problem
 PHP Version:        7.2.7
 Assigned To:        jasny
 Block user comment: N
 Private report:     N

 New Comment:

> The semicolon is not required *for the heredoc itself*. You
> still have to write valid code, […]

Right.  Changing to doc problem.


Previous Comments:
------------------------------------------------------------------------
[2019-04-03 19:18:21] [email protected]

Yeah. Easily.

echo <<<FOO
abcdefg
FOO, "hijk";

------------------------------------------------------------------------
[2019-04-03 19:09:09] chasepeeler at gmail dot com

Can you provide an example where you would ever not need a semicolon at the end of the heredoc, then?

------------------------------------------------------------------------
[2019-04-03 18:07:55] [email protected]

> However, if you don't include a semicolon, you get an error:
The semicolon is not required *for the heredoc itself*. You still have to write valid code, and

  $str = "
  abcdefg"

  echo $str;

is not valid code.

------------------------------------------------------------------------
[2019-04-03 17:47:55] chasepeeler at gmail dot com

Yes, in 7.3, the documentation states:
"The closing marker for doc strings is no longer required to be followed by a semicolon or newline."
https://www.php.net/manual/en/migration73.new-features.php#migration73.new-features.core.heredoc

However, if you don't include a semicolon, you get an error:

<?php

$str = <<<FOO
abcdefg
FOO

echo $str;

> Parse error: syntax error, unexpected 'echo' (T_ECHO) in /in/eTKHe on line 7

If you add a semicolon after FOO, everything works. This is against 7.3.3:
https://3v4l.org/eTKHe

------------------------------------------------------------------------
[2018-07-11 17:57:49] mattacosta at gmail dot com

That error appears to be correct in previous versions though. Without the required  line break, the label would be part of the text instead, so it would make sense to expect T_END_HEREDOC.

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=76608


--
Edit this bug report at https://bugs.php.net/bug.php?id=76608&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.