On Bashing PHP 20 Feb, 2006
Wow, there has been an awful lot of response to this post, requiring
substantial updates, so I went ahead and redid the whole post to incorporate
them. I wasn’t aware that this would be automagically linked from the
referenced post, and was not expecting so many rude comments. Let me please
note that if you have snide remarks, my email is tim@timhatch.com.
Unsigned comments will not be published, period.
Overall, my experience is not that php is great or not great, simply that
it is both efficient and adequate for what it is billed as: a hypertext
preprocessor. As long as you don’t expect organizational miracles to come
from its use, it’s not bad. Expecially when coupled with something like
Apache’s mod_rewrite.
Tim Bray previously posted an article “On PHP” which summed up my basic opinions on the issue as well. PHP is easy to use. PHP is better that some alternatives (see Perl) in terms of understanding what something was supposed to do, although it’s not terribly good in being able to reuse it.
PHP is not designed around modules. It has no real concept of namespaces,
although you can use classmethods as kind of a hack around this. Even then,
you ought to keep a singleton around (in the global namespace) if you intend
to keep around faux-module-level variables. This is something that IMO Python
has gotten right very early on. Simply set $PYTHONPATH before
running the script or modify sys.path while running, and
that’s where it will start looking for packages. This makes it very
easy to set up development environments, whereas PHP requires a modification
to the systemwide php.ini in order to alter the include paths.
In one comment, unsigned and thus not published, someone mentioned the
ability to use php_value in .htaccess files. This is a workaround
for include paths, but doesn’t work when run from the console.
I claimed that there was no acceptable PHP debugger, and was subsequently pointed to three, one of which looks like it would work nicely. Although not on NetWare, because nothing works on NetWare.
I claimed that Perl’s DBI and Python’s PyDBO de facto standard database layers were better than PHP’s, mainly because a good one doesn’t exist for php. One person pointed me to PDO, "included in PHP5.1," and another mentioned ADODB. ADODB does not behave on NetWare, and seems to be finicky on other OSes. When I code, it’s simultaneously for Win32-Apache2.0-PHP4, MacOSX-Apache1.3-PHP4, GentooLinux-Apache2.0-PHP4, DebianLinux-Apache1.3-PHP4, and RollYourOwnLinux-Apache2.0-PHP5CGI (from source). ADODB is used by a number of projects, including Gallery, which is the slowest php webapp I’ve ever used.
Exceptions are nice in PHP5, as would be PDO, but as you can see from the previous list, my supported platforms are (for the most part) PHP4. This is why I’ve ended up writing a lot of wrappers myself, to avoid writing ugly code over and over (instead writing it once, then not having to look at it again).
Will I continue to use PHP in my everyday life? Yes, I certainly will. Why? Because I can get things done in it. In the short term, I think that’s what matters.
"This is a workaround for include paths, but doesn’t work when run from the console." What about set_include_path()? http://php.he.net/set_include_path
Typo?: "I claimed that Perl's DBI and PHP's PyDBO de facto standard database layers were better than PHP's[...]"
Thanks, typo fixed.