NYCPHP Meetup

NYPHP.org

[nycphp-talk] Can code be executed in a heredoc?

Adam Fields adam at digitalpulp.com
Wed Feb 18 11:45:32 EST 2004


James Wetterau wrote:

> Adam Maccabee Trachtenberg says:
> 
>>On Tue, 17 Feb 2004, Daniel J Cain Jr. wrote:
>>
>>
>>>Is it bad form to use the format below?  Instead of escaping all double
>>>quotes to use single quotes for the tag attributes.
>>>
>>>echo "<a href='http://www.nyphp.org'>Link Test</a>";
>>
>>While that is technically legal HTML, until someone can prove it to me
>>otherwise, I've never trusted that some stupid browser won't barf on
>>it.
> 
> 
> I've used single quotes for precisely this reason off and on since
> about 1995.  It never even occurred to me to worry about it.  I've
> never once seen a problem with doing this, but then I've only had nine
> years of sporadic experience with it so far.

However, there is a slight PHP performance issue with this. Single 
quotes are MUCH faster for the interpreter to process, as there's no 
interpolation.

As a general rule, I understand that you should use single quotes to 
delimit PHP strings whereever you can, to cue the interpreter that no 
interpolation is necessary.

I'm pretty sure that there's a speed difference between this:

echo '<a href="http://www.nyphp.org">Link Test</a>';

and this:

echo "<a href='http://www.nyphp.org'>Link Test</a>";

But it should be easy enough to test.


More particularly, there should also be a performance difference between 
this:

$someurl = 'http://www.nyphp.org';
echo '<a href="'. $someurl .'">Link Test</a>';

and this:

$someurl = 'http://www.nyphp.org';
echo "<a href='$someurl'>Link Test</a>";



More information about the talk mailing list