Exactly what I was thinking. I've worked on code with these sorts of optimizations, and any gains in speed over the life of the site were negated by my time having to figure out what the heck was going on. Maybe most or even all of these tricks will save nanoseconds here or there, but a good architecture and well-written code are better in the long run.
But...it runs everywhere, and is only compiled when code changes are made...unlike php which is interpreted every time...unless you use Zend or something like it...which kinda defeats the purpose of using a scripting language.
Speaking of calling a length function on a string inside a for loop : That was a test case for an assignment during our second year of CS, which a lot of students missed. How often does this happen in a production environment ? Thanks for the article. That was a nice read.
As per the ternary operator; I have agreed to take a look at a page that used a php templating library which was riddled with ternary ops everywhere. That s**t was as much fun as reading obfuscated code ;(
Some irritation I see in updating other developers code, is that there are still people who don't template there output. At the very least, you can come up with a templating scheme like <a class="user" href="http://webdevxchange.com/node/7">http://webdevxchange.com/node/7</a>Secondly, I would suggest using some sort of fore-thought like abstract classes or interfaces to reduce the nuisance of repeated code or common objects etc.
Unlike the suggested way, I normally add the code to not cache the page because cached pages in PHP really are not good as it prevents you from getting the most recent/fresh content. Specially when using get function to submit a form and getting the result if you have not used a code instructing to not cache the page, more is chance you will get the old results and if page code or functions are updated but you using the same input parameter then, I am sorry you are getting old results.---PHP coding Tips N Tricks:<a class="user" href="http://codingtricks.blogspot.com">http://codingtricks.blogspot.com</a>
csixty4Oct 16, 2007
Exactly what I was thinking. I've worked on code with these sorts of optimizations, and any gains in speed over the life of the site were negated by my time having to figure out what the heck was going on. Maybe most or even all of these tricks will save nanoseconds here or there, but a good architecture and well-written code are better in the long run.
ellisglOct 16, 2007
++$i is only in PHP.Also ++$i can cause problems in certain cases.
steggOct 16, 2007
One step for optimizing your PHP code:1) Use Ruby on Rails
chris1outOct 17, 2007
But...it runs everywhere, and is only compiled when code changes are made...unlike php which is interpreted every time...unless you use Zend or something like it...which kinda defeats the purpose of using a scripting language.
chris1outOct 17, 2007
Good to see another Java programmer in this sea of PHP junkies.
aickieranOct 21, 2007
Which is slower than php and almost every other language, take off the ruby colored glasses.Bad programmers write bad code, regardless of language.
wildmxranatNov 5, 2007
Speaking of calling a length function on a string inside a for loop : That was a test case for an assignment during our second year of CS, which a lot of students missed. How often does this happen in a production environment ? Thanks for the article. That was a nice read.
wildmxranatNov 5, 2007
I liked the clarity and that it didn't overwhelm my screen with google ads.
wildmxranatNov 5, 2007
As per the ternary operator; I have agreed to take a look at a page that used a php templating library which was riddled with ternary ops everywhere. That s**t was as much fun as reading obfuscated code ;(
aadhunikNov 6, 2007
nice list of tips
echophpFeb 7, 2008
Yes do .PHP is worth learingUpdate your knowledge in the world of web programming with the latest updated .<a class="user" href="http://www.websitescript.blogspot.com">http://www.websitescript.blogspot.com</a><a class="user" href="http://www.echophp.tk">http://www.echophp.tk</a>
echophpFeb 7, 2008
I agree with the tips . that is great . keep it up .Update your knowledge in the world of web programming with the latest updated .<a class="user" href="http://www.websitescript.blogspot.com">http://www.websitescript.blogspot.com</a><a class="user" href="http://www.echophp.tk">http://www.echophp.tk</a>
sureshnsnguysMay 20, 2008
Nice information . It helped me a lot
hm2kMay 20, 2008
Try this -> <a class="user" href="http://www.hm2k.com/posts/50-php-optimisation-tips-revisited">http://www.hm2k.com/posts/50-php-optimisation-tips ...</a>
Closed AccountAug 27, 2008
Actually, some douchebags made it up already:<a class="user" href="http://en.wikipedia.org/wiki/Web_3.0">http://en.wikipedia.org/wiki/Web_3.0</a>
webguy1620Sep 21, 2008
Some irritation I see in updating other developers code, is that there are still people who don't template there output. At the very least, you can come up with a templating scheme like <a class="user" href="http://webdevxchange.com/node/7">http://webdevxchange.com/node/7</a>Secondly, I would suggest using some sort of fore-thought like abstract classes or interfaces to reduce the nuisance of repeated code or common objects etc.
aaryn015Dec 25, 2008
What a pair of f**king nerds. Arguing over which programming language is the best.Honestly, get a life.
aaryn015Dec 25, 2008
One step for making yourself look like a lifeless nerd:1) Find PHP threads on Digg and troll over other languages.
khu84Feb 9, 2009
Unlike the suggested way, I normally add the code to not cache the page because cached pages in PHP really are not good as it prevents you from getting the most recent/fresh content. Specially when using get function to submit a form and getting the result if you have not used a code instructing to not cache the page, more is chance you will get the old results and if page code or functions are updated but you using the same input parameter then, I am sorry you are getting old results.---PHP coding Tips N Tricks:<a class="user" href="http://codingtricks.blogspot.com">http://codingtricks.blogspot.com</a>
kvganesanFeb 17, 2009
it's simple and good
aiahoosSep 3, 2010
Thanks I like it. I can also recommend http://phpforms.net/tutorial/tutorial.html