Req #66303 [Com]: Inline Heredoc / Nowdoc

From: Date: Tue, 17 Dec 2013 02:20:54 +0000
Subject: Req #66303 [Com]: Inline Heredoc / Nowdoc
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-183365@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66303&edit=1

 ID:                 66303
 Comment by:         mail at requinix dot net
 Reported by:        childerkc at gmail dot com
 Summary:            Inline Heredoc / Nowdoc
 Status:             Open
 Type:               Feature/Change Request
 Package:            *General Issues
 Operating System:   CentOS Linux
 PHP Version:        5.5.7
 Block user comment: N
 Private report:     N

 New Comment:

Inline heredoc and nowdoc... So you mean normal string syntax? Surely
  '#someID{width: 100px; height: 100px}'
is "sexier" than
  <<<'CSS'>#someID{width: 100px; height: 100px}<CSS>>>


Previous Comments:
------------------------------------------------------------------------
[2013-12-17 01:29:00] childerkc at gmail dot com

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 this bug report at https://bugs.php.net/bug.php?id=66303&edit=1


Thread (5 messages)

« previous php.bugs (#183365) next »