If we do want to add to the language, there's also NOWDOC syntax to
take into account.
I tend to use heredocs mostly for SQL, BTW ; something like:
<?php
$request = <<<SQL
(some sql)
SQL;
makes a very readable delimitation of the SQL from the enclosing PHP code.
2013/2/24 FGM at GMail <fgma...@gmail.com>
If we do want to add to the language, there's also NOWDOC syntax to
take into account.
I tend to use heredocs mostly for SQL, BTW ; something like:
<?php
$request = <<<SQL
(some sql)
SQL;
makes a very readable delimitation of the SQL from the enclosing PHP code.Also some ideas (namely PhpStorm (don't now, if any other is capable of this)) is able to inject code highlighting for heredoc-strings with special heredoc-markers like "<<<SQL" for SQL and "<<<JS" for Javascript.
--
Personally I'm finding heredocs useful on some WordPress projects (which generally encourage HTML, JavaScript etc embedded in PHP), but the main problem is the indentation. As soon as you enter a heredoc, you are entering an embedded document with its own indentation and indenting rules, and that can be quite difficulty to follow at times. So my heredocs end up being moved out to external files (templates, I guess).
$myhtml = include('mytemplate.php');
mytemplate.php:
<?php
// Initialise/escape template variables
return <<<HTML
<div>whatever</div>
HTML;
I'm not sure if that example helps, but in general I feel it means heredocs should in general be discouraged in mainly PHP scripts as it can make the code more difficult to follow, but you cannot deny it helps testing some quick hacks. For the amount of use it gets, I don't think it would help to be mentioned in a PSR.
-- Jason
On Sunday, 24 February 2013 13:51:07 UTC, Chuck Reeves wrote:There is no spec about how this should be handled. Is it discouraged? Can we embed them in functions or put before or after class definitions? Any thoughts about this?This came to mind while im working on a ZF2 project using mongo and some map reduce functions. I want to use heredoc to define the functions for readability.
--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+u...@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/php-fig/-/JE2EVEpf_4gJ.