> -----Original Message-----
> From: Ahmed Mohsen [mailto:mre...@gmail.com] 
> Sent: Friday, June 11, 2010 4:25 PM
> To: php-general@lists.php.net
> Subject: Re: [PHP] is <?= good?
> On 6/11/2010 11:43 PM, Daevid Vincent wrote:
> >> -----Original Message-----
> >> From: tedd [mailto:tedd.sperl...@gmail.com]
> >>
> >> I believe, just because it can be done doesn't mean that it
> >> should be done.
> >>
> >> My practice is *never* to use<?=
> >>
> >> In fact, my practice is to not only use<?php echo, but to enclose
> >> the echo argument with a (), like:
> >>
> >> <?php echo("The answer is $answer");?>
> >>
> >> I am sure there will be some that think that my practice is an
> >> overkill, or not "good practice", but it's a good thing that we all
> >> have a choice. Make your choice to best serve how you want 
> your code
> >> to look.
> >
> > As per http://us3.php.net/echo
> >
> > echo() is not actually a function (it is a language 
> construct), so you are
> > not required to use parentheses with it. echo() (unlike 
> some other language
> > constructs) does not behave like a function, so it cannot 
> always be used in
> > the context of a function. Additionally, if you want to 
> pass more than one
> > parameter to echo(), the parameters must not be enclosed within
> > parentheses.
> >
> > So you might want to reconsider your coding practice/style 
> here and use the
> > construct as designed or you might end up with a far worse 
> scenario than
> > short-tags could ever provide. Something more along the 
> Python "print"
> > debacle.
> >
> > Also, for the love of God, please don't embed a variable 
> into a literal
> > string and use preprocessing.
> >
> > Do it like so:
> >
> > <?php echo 'The answer is '.$answer; ?>
> >
> Hey Daevid, does this form <?php echo 'The answer is '.$answer; ?> 
> improve anything in processing time or it's just for the sake of 
> readability?

Technically it does have a microscopic speed increase, but unless you're
pumping out hundreds or thousands of lines (like in a loop) you most likely
won't notice it. In my code, I always try to use the proper quote marks
because I *am* dealing with huge tables of data. I've said this a hundred
times before, if you can shave off 0.001 from each row, then after 1,000
rows, you've shaved 1 second off the page time. That seems small, but that
shit adds up. Caching will help, as the page is already parsed once, so PHP
doesn't have to do the work again in many cases. To me, it's a good habbit
and costs you nothing to do.

The difference is that with " the PHP engine has to pre-process the string
and look to see if there's anything interesting it needs to do -- such as
replace any $var with their equivalents or \n or whatever else. A ' means
to use it as is, so PHP just spits it back out.




PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to