Req #66303 [NEW]: Inline Heredoc / Nowdoc

From: Date: Tue, 17 Dec 2013 01:29:01 +0000
Subject: Req #66303 [NEW]: Inline Heredoc / Nowdoc
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-183364@lists.php.net to get a copy of this message
From: childerkc at gmail dot com Operating system: CentOS Linux PHP version: 5.5.7 Package: *General Issues Bug Type: Feature/Change Request Bug description:Inline Heredoc / Nowdoc Description: ------------ I use heredoc and nowdoc at times, and feel they are very powerful if you know why your using them. With that, I wish they were sexier when it came to the syntax, I am not a fan of commands to go in and out of a heredoc, being on their own line. This tends to get annoying if you are trying to pass a bunch of different pieces of data to different parameters of a function. An example could be found in the test script below Test script: --------------- // Obviously not the most logical function in this case, but point still holds true, heredocs are ugly and don't need to be... function foo($css,$js,$html) {handleCSS($b);handleJS($r);return $html;} if($someTrueCondition) { echo foo( <<<'CSS' #someID{width: 100px; height: 100px} CSS , // <---------- :( <<<'JS' alert("simple alert"); JS , // <---------- :'( <<<'HTML' <div id="someID">$SomeOtherInnerHTML</div> HTML ); } // The above code just makes me want to cry... such lonely random commas... // Why instead, can this not be simplified? I have seen some other bug requests that just make the heredocs more complicated.. my goal is to not make them any more complicated, just to simplify the usage of them for us developers who do use them [maybe more then we should]... My Proposal is to simply allow them to be inline like the rest of the code? And instead, maybe simply allow them follow the flow of the developers ohh so beautiful code.. so.. // The only thing one would need to do is to instead make sure that the start of a heredoc is at the END OF A LINE, and the END of a heredoc, is at the START of a line, EXCLUDING ALL DATA BEFORE START TAG AND AFTER END TAG... So the above ugliness, becomes a little easier on the eyes: if($someTrueCondition) { echo foo(<<<'CSS' #someID{width: 100px; height: 100px} CSS, <<<'JS' alert("simple alert"); JS, <<<'HTML' <div id="someID">$SomeOtherInnerHTML</div> HTML); } // And if an ending heredoc starts on a line, then breaks out of heredoc, it can then go back in to it, on the same line, at the END of the line... I would also say that the heredoc should then handle removing any white space in the content for each line that is equivalent to the whitespace before the END tag for that heredoc... This would keep the code beautiful and the end result beautiful.. (maybe even leave the content alone, white space and all, no worries for me as something cleans if up for me later anyway).. // What I would LOVE to see, is the heredoc in an actual INLINE way... So that the above 2 ugly's become the sexy code below... This would mean the syntax would probably need to change a little, start tag would be something simple like <<<'EOD'> and the end tag would be the opposite without the quotes <EOD>>>, everything between the > and < would adhere to the heredoc standards... if($someTrueCondition) { echo foo( <<<'CSS'>#someID{width: 100px; height: 100px}<CSS>>>, <<<'JS'>alert("simple alert");<JS>>>, <<<'HTML'><div id="someID">$SomeOtherInnerHTML</div><HTML>>> ); } -- Edit bug report at https://bugs.php.net/bug.php?id=66303&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66303&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66303&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66303&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=66303&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=66303&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=66303&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=66303&r=needscript Try newer version: https://bugs.php.net/fix.php?id=66303&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=66303&r=support Expected behavior: https://bugs.php.net/fix.php?id=66303&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=66303&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=66303&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=66303&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66303&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=66303&r=dst IIS Stability: https://bugs.php.net/fix.php?id=66303&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=66303&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=66303&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=66303&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=66303&r=mysqlcfg

« previous php.bugs (#183364) next »