note 113857 added to language.types.string
| From: | espertalhao04 at hotmail dot com | Date: | Tue, 10 Dec 2013 10:34:12 +0000 |
| Subject: | note 113857 added to language.types.string | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-197891@lists.php.net to get a copy of this message | ||
gtisza at gmail dot com
You incorrectly stated that thee documentation doesn't refer anything about the semicolon at
the end of the heredocs and nowdocs being interpreted as a "real" semicolon.
If you read carefully, you will notice this, in the 1st sentence of the warning about heredocs:
"It is very important to note that the line with the closing identifier must contain no other
characters, except a semicolon (;)."
Interesting...
It is refering about semicolons...
But wait, there is more:
http://php.net/manual/en/language.basic-syntax.instruction-separation.php
1st sentence says:
"As in C or Perl, PHP requires instructions to be terminated with a semicolon at the end of
each statement."
So, here says that semicolons are statement separators, basicly...
So, if you put a "real" semicolon at the end of these examples:
<?php
$a=5;
$foo="String";
$bar=array();
$yep=null;
$other=func();
?>
Why shouldn't you put at the end of heredocs and nowdocs?
After all, a heredoc or a nowdoc is simply a string.
You should read more carefully the documentation first before saying any comment.
About serious questions:
I didn't read all comments here, but you can run functions inside strings and heredocs.
And you can even nest them inside {}
Example:
<?php
$f=function($x){$a=func_get_args();unset($a[0]);return call_user_func_array($x,$a);};
$d=0;
echo $b=<<<NUMBERS
4.0909 rounded is: {$f('round',4.0909,$d)}
Time now is: {$f('time')}
Nested heredocs/nowdocs: {$f('sprintf',<<<OTHER
Here is an %s of nested %s
OTHER
,"Example",<<<'NOW'
heredocs and nowdocs
NOW
)}
NUMBERS;
/*echoes (time is system and real time relative):
4.0909 rounded is: 4
Time now is: 1386670912
Nested heredocs/nowdocs: Here is an Example of nested heredocs and nowdocs
*/
?>
It's not pretty, and is hard to read, but sometimes it is useful to confuse curious people
(like minifying the code).
Warning: if any function that runs inside a string or heredoc gives a fatal error, the script MAY
continue!
----
Server IP: 72.52.91.14
Probable Submitter: 72.52.91.14
----
Manual Page -- http://php.net/manual/en/language.types.string.php
Edit -- https://master.php.net/note/edit/113857
Del: integrated -- https://master.php.net/note/delete/113857/integrated
Del: useless -- https://master.php.net/note/delete/113857/useless
Del: bad code -- https://master.php.net/note/delete/113857/bad+code
Del: spam -- https://master.php.net/note/delete/113857/spam
Del: non-english -- https://master.php.net/note/delete/113857/non-english
Del: in docs -- https://master.php.net/note/delete/113857/in+docs
Del: other reasons-- https://master.php.net/note/delete/113857
Reject -- https://master.php.net/note/reject/113857
Search -- https://master.php.net/manage/user-notes.php