note 113857 deleted from language.types.string by cmb

From: Date: Sun, 04 Aug 2019 09:18:45 +0000
Subject: note 113857 deleted from language.types.string by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-211814@lists.php.net to get a copy of this message
Note Submitter: espertalhao04 at hotmail dot com ---- 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!

« previous php.notes (#211814) next »