php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #26582 HEREDOC linefeed requirement mis-documented
Submitted: 2003-12-10 09:12 UTC Modified: 2004-02-17 12:27 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: iwd32900 at yahoo dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.3.4 OS: Darwin/Mac OS X
Private report: No CVE-ID: None
 [2003-12-10 09:12 UTC] iwd32900 at yahoo dot com
Description:
------------
The current manual says this, under the "Heredoc" 
section in "Strings" in "Types":

-----
It's also important to realize that the first character 
before the closing identifier must be a newline as 
defined by your operating system. This is \r on 
Macintosh for example.

If this rule is broken and the closing identifier is not 
"clean" then it's not considered to be a closing 
identifier and PHP will continue looking for one. If in 
this case a proper closing identifier is not found then 
a parse error will result with the line number being at 
the end of the script.
-----

I have two issues with this.
1. This doesn't appear to be true. I'm using the 
entropy.ch distribution of 4.3.4, and it accepts \n as a 
linefeed before the end marker on my Mac.

2. One of the great things about PHP is that it's cross-
platform portable. The interpretter otherwise seems to 
be linefeed-agnostic; it should be here, too. That way, 
I can write my scripts on any platform and distribute 
them to any other, and no one has to worry about 
something as irritating as linefeeds. Just check for any 
of \n, \r, or \r\n before a heredoc terminator. Should 
be really easy, and it will do a lot for making PHP more 
platform independent.

Reproduce code:
---------------
$heredoc = <<<HEREDOC
    Does this cause a parse error?
HEREDOC;
echo $heredoc;

// No, it doesn't

Expected result:
----------------
Given what the manual says, this should break since the 
linefeeds are Unix but it was run on a Mac.

The documented behavior isn't the DESIRABLE behavior, 
however. PHP should accept all linefeed types on all 
platforms to promote code portability.

Actual result:
--------------
The example works just fine on my Mac, actually. It may 
be that the cross-platform behavior is already 
implementd, and just hasn't been documented yet.

Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-12-10 09:39 UTC] vrana@php.net
Does heredoc work for you with \r?
 [2003-12-18 05:21 UTC] sniper@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 [2003-12-18 08:13 UTC] iwd32900 at yahoo dot com
No, it doesn't work with \r.

I realize that in some sense, \n is the new 'native' 
linefeed for Mac since OS X is Unix based. This doesn't 
change my opinion that PHP should be linefeed-agnostic, 
so that code can easily be transported from one platform 
to another.
 [2004-02-17 12:27 UTC] irchtml@php.net
The documentation seems pretty clear on this.

Status -> Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Aug 17 04:01:29 2024 UTC