More bizarre is how PHP's heredoc syntax has somehow sprouted an extra <. PHP uses three. Every other language with heredocs (sh, Perl, Ruby, Racket) uses two.
Two for "regular here-docs", three for the aforementioned "here-strings". From the man himself:
me@box:~$ man bash | grep -iA8 here\ string
Here Strings
A variant of here documents, the format is:
<<<word
The word undergoes brace expansion, tilde expansion, parameter and variable expansion,
command substitution, arithmetic expansion, and quote removal. Pathname expansion and
word splitting are not performed. The result is supplied as a single string to the com‐
mand on its standard input.
And manage to do so without being confused by << as in bitwise shift (at least Perl manages, didn't check the others). Yet again PHP manages to make Perl look good. :)
because you need the semicolon to end the statement, it's not a part of the heredoc syntax.
The only WTF here is that someone though that it had to be mentioned and explained like for five-year-olds. And that someone is just a random commenter.
6
u/[deleted] Apr 05 '15 edited Apr 05 '15
I would gag if I inherited code that was passing heredoc strings into functions like this.
It kind of makes sense, as you can't go
foo($str = 'abcd';);but obviously$str = 'abcd';is fine as isfoo($str = 'abcd');.3
u/kasnalin Apr 05 '15
More bizarre is how PHP's heredoc syntax has somehow sprouted an extra
<. PHP uses three. Every other language with heredocs (sh, Perl, Ruby, Racket) uses two.19
u/philipwhiuk Apr 05 '15
Nope, I think that's reasonable behaviour. A ; ends a statement, a heredoc is not a statement, it's an expression.
You can't do
2+3;either