10 Advanced PHP Tips Revisited

2013 年 10 月 8 日7330

Certainly an improvement over the earlier article, but there still seems to be an unhealthy obsession with micro-optimization resulting in less readable code. The isset trick might save you a microsecond but it’s intent is less clear than strlen.

The place where the biggest gains can be made when it comes to optimizing PHP are almost always in the sections that talk to the database. There are plenty of mistakes that it is very easy to make here, even for seasoned programmers, such as asking for more data than you need or asking for the same data more than once. If you always check before querying that you already have the data you need, and if you are careful to only query the database to get what you need and nothing else, you’ll speed your code up far more than replacing strlen with isset.

As for SQL injection, why have you not mentioned prepared statements? Using them make injections far more difficult to achieve, and have the added benefit of speeding up repetitive queries.

0 0