From:             ssilk at fidion dot de
Operating system: 
PHP version:      Irrelevant
PHP Bug Type:     Feature/Change Request
Bug description:  Heredoc-Syntax

Description:
------------
I read the bug #13610 and other depending stuff and I think the core of
the problem is, that heredoc-syntax is some kind of confusing, because of
the sensitivity for whitespace-characters (Space, Tab, CR, LF...) (and
perhaps the fixating for the OS-newline-character).


Here are some examples of realy time-consuming error-searches:

// example #1
echo <<<heredoc 
There is a SPACE between
the identifier and the end of line;
PHP thinks now, the identifier is
"heredoc " (with space at the end)
and not "heredoc" as assumend.
heredoc;
// fails, instead PHP thinks
// it is still inside the heredoc
// so it prints out very funny error messages.
//
// Here is a tip for the documentation:
//
// This case could be tested easily if you type something
// looking like a "array-var" like $a['b']
// If PHP says there is an error in the line above
// then you have the "whitespace-identifier-problem".
// (the ' is important here! Perhaps there are some
// other testcases)

// example #2
echo <<<heredoc
Now we made all right above, but
for more readable code we added a space
before the semicolon at the end:
heredoc ;
// same problem as above, but the other way around. :)

This problem is not very obvious to even experienced programmers.

So currently a developer must try to avoid any whitespaces in conjunction
with heredoc-identifiers!

I suggest here (see bug #5804 at the end, feature request by Hartmut) to
change the parser to stop parsing the identifier if it finds a whitespace.
I think this avoids many problems with it and I think the current
implementation provokes missinterpretation.

Perhaps - to enable more complicated stuff - adding a new heredoc-syntax
like 

echo <<<<tag-like-syntax...>This is a tag-like syntax...
The end of the string 
is marked with <\/tag-like syntax...>
(the above \\/-escape sequence
must be added to this routine). 
The end can exist in the same line
and not only at the
begin of a line</tag-like-syntax...> ; // end of string

Think, this kind of heredoc is very "readable", cause every PHP-user knows
what a tag is and how it works. This also comes into some direction to
Pearl (the ugly q-syntax, I realy hate it :), but this is some more
nicer.

Perhaps some special ideas here. Just implementing tag-like strings, it
could be useful to also add arguments:

      echo <<<<string ignore_indent=1 strip_nl>
      This enables you to indent the string,
      but in the output the indenting is stripped away.
      Also it deletes the newlines at the begin and
      end of the string.
      </string>

Some more (very useful) arguments are thinkable.

A more intelligent error handling in cases, when inside a heredoc-string
an error occours, could also help a lot (printing out the found identifier
within quotes) or a error-message, that the awaited identifier isn't valid
or something like this kind.

All in all heredoc is very useful. See also the useful feature request in
Bug #8685 ('<<-'-syntax).




-- 
Edit bug report at http://bugs.php.net/?id=24750&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=24750&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=24750&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=24750&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=24750&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=24750&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=24750&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=24750&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=24750&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=24750&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=24750&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=24750&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=24750&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=24750&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=24750&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=24750&r=gnused

Reply via email to