Re: I am RTFM, but still stumbling on how to get built-in functions parsed in heredoc

From: Date: Sat, 11 Jul 2009 17:26:50 +0000
Subject: Re: I am RTFM, but still stumbling on how to get built-in functions parsed in heredoc
References: 1 2 3 4 5  Groups: php.general 
Request: Send a blank email to php-general+get-295227@lists.php.net to get a copy of this message
On Sat, Jul 11, 2009 at 11:03 AM, Daniel Brown<danbrown@php.net> wrote: > On Sat, Jul 11, 2009 at 10:42, Ashley Sheridan<ash@ashleysheridan.co.uk> wrote: >> >> The braces ensure that PHP doesn't stop parsing the variable name once it >> reaches the [. By default, it will only match a variable name up to the [ >> sign, so you couldn't access arrays without the braces. > >    Couldn't have said it better myself. > >    As for the braces in the HEREDOC around {$somevar}, while it works > absolutely fine, it was a typo on my part: I intended to show all > manner of usage and processing of variables within the HEREDOC syntax. >  However, in my own code, I generally include all variables between > {braces} when inside a HEREDOC block.  Sheer preference for > readability in a large HEREDOC: because I don't normally use curly > braces around variables, when I see that on the page, I instantly > recognize that I'm still in the block (if all other clues miraculously > fail --- and we all know that they sometimes do). > > -- > </Daniel P. Brown> > daniel.brown@parasane.net || danbrown@php.net > http://www.parasane.net/ || > http://www.pilotpig.net/ > Check out our great hosting and dedicated server deals at > http://twitter.com/pilotpig > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > Uhm.... you don't need braces around arrays unless you're using more than one dimension in the array. This works perfectly fine for me: <?php $bar = array('hello' => "goodbye"); $foo = <<<EOT $bar[hello] EOT; echo $foo; //echos out goodbye ?> Something this simple should be common knowledge :X but I still agree with Daniel that you ought to use {} around variables in HEREDOC (or double-quotes) as it makes your code much more readable.

« previous php.general (#295227) next »