
10 Advanced PHP Tips To Improve Your Programming - qhoxie
http://www.smashingmagazine.com/2008/11/18/10-advanced-php-tips-to-improve-your-progamming/
======
k4st
None of those are particularly interesting or lead to better coding practices.

For example: dropping braces for block statements is a convention; it doesn't
inherently make someone a better programmer. It's also not by any means
'advanced'.

Also, the else shortcut should be seen as having different syntactic meaning.
Instead of emphasizing it as a convenient shortcut, it should be seen as a
particular variable has a default state and belongs to the lexical scope that
the if statement is contained within (even though PHP doesn't recognize block
statements as new lexical scopes).

Finally, ereg_ functions should never be used. And favoring str_* over preg_*
only makes sense when a non-trivial[1] regular expression is not involved. The
suggestion is tantamount to saying use a function for it's intended purpose.
str_* functions search using a string, preg_* search using regular
expressions.

[1] By non-trivial I mean a pattern that involves more than a terminal. E.g.
'~hello~' is a valid regular expression but is composed of a single terminal,
'hello' (or if you wan to see it as five terminals) but nothing else (e.g.
repeating, conditions, etc.) and so '~hello~' is a case where preg_* functions
are overkill.

~~~
aasarava
Just curious: Why are ereg_ functions never to be used? If you need to handle
POSIX compatible regular expressions instead of PCRE, wouldn't you use ereg_
instead of preg_ ? (Or am I wrong about this?)

~~~
k4st
For some reason I thought that the ereg_* functions were deprecated; that's
not the case. I was wrong in saying they should never be used; however, it
remains the case that preg_* is usually faster.

