Re: Variable as an index

From: Date: Sun, 21 Dec 2008 23:50:58 +0000
Subject: Re: Variable as an index
References: 1 2 3 4 5 6 7  Groups: php.general 
Request: Send a blank email to php-general+get-284945@lists.php.net to get a copy of this message
True, it might mean the very slightest in milliseconds...depending on what you're doing/hardware. However, no harm in understanding the difference/how it works. Many will code echo "Hello World" and echo 'Hello World'; and never know the difference, I just happen to think being aware of the details will help for the long term programmer. Since, I brought it up, I'll go ahead and give another example. Ternaries that make a lot of people feel awesome because a lot is being accomplished in one line are also more opcodes than their if-else statement equivalents...and often times can be more confusing to future maintainers of the code. Anthony Gentile On Sun, Dec 21, 2008 at 6:20 PM, Chris <dmagick@gmail.com> wrote: > Anthony Gentile wrote: > >> for e.g. >> $var = 'world'; >> echo "hello $var"; >> vs >> echo 'hello '.$var; >> >> The first uses twice as many opcodes as compared to the second. The first >> is >> init a string and adding to it the first part(string) and then the second >> part (var); once completed it can echo it out. The second is simply two >> opcodes, a concatenate and an echo. Interpolation. >> > > I'd call this a micro-optimization. If changing this causes that much of a > difference in your script, wow - you're way ahead of the rest of us. > > > > http://blog.libssh2.org/index.php?/archives/28-How-long-is-a-piece-of-string.html > > http://www.phpbench.com/ > > -- > Postgresql & php tutorials > http://www.designmagick.com/ > >

« previous php.general (#284945) next »