First off however is what I don't like about PHP, since I can't say I'm gushing happiness with the language. I don't like the syntax (with the exception of sigils and double-quote-inlining) and their choice of OOP implementation that's an unholy mix of C++ and Java. After years of Python and a few decently sized projects in Clojure, coming back to PHP feels like just a nicer version of Java. (Of course, after years of programming Java, I don't particularly hate it either...) I don't like the function argument order ambiguity and inconsistency, a problem that is mitigated through memorization and "php.net/func-name" but would be best mitigated with specifying default arguments at call-time in a way similar to what Python allows, which makes remembering the order irrelevant. I also think PHP could be faster, given I think of it as "the C of the web" (which will probably generate some hate). I hate the choice of a backslash for namespaces. I hate the lack of $_PUT and $_PATCH and $_CUSTOM and so on. Sometimes I pine for a REPL. I wish it handled utf-8 better. I wish it supported multiple inheritance.
That about sums up my issues with modern (>= 5.3) PHP. God help you if you're still supporting PHP 4 code.
I'm not turned off by the "everything in global namespace" feature. C does the same thing (albeit forces you to include the parts of the standard library you want, unlike PHP), and in both C and PHP there are ways to manage your personal namespace if it bothers you. (More so in PHP with the introduction of actual namespaces, which I've yet to use since class-wrapped scope is Good Enough for me.) The reason it doesn't bother me is because I don't use PHP as a general-purpose language, I use it as a web-language. Having access to all the important web-specific functions without including separate modules is a joy, but it would suck if I was developing a video game or something that didn't need such functions.
I like the Yii framework, to the extent I like frameworks at all. It makes MVC fairly painless and does a lot of work for you. Yii is on par with RoR and Django, though it does have its pain-points.
I like Smarty, but find it unnecessary. I still love PHP's ability to inline with regular HTML which makes it an instant template language among everything else. Not the most concise template language, but it's still pretty concise, and most web designers shouldn't be frightened by its presence whereas they might lose their marbles if they ever encounter the elegant (html (head (title "blah")) (body (div (h1 "Hi")))) you might find in a Lisp application.
PEAR is nice, sometimes.
I like that PHP is more or less the standard of web development. It's easy enough for artists to get around in, and powerful enough to allow for clever abstractions. All the cheap shared web hosts support it, along with a bunch of free hosts too. It's easy to use with Apache (such as using mod_rewrite).
I like that it grew out of imperative programming roots rather than OOP roots, I think it's a better language because of it. If you think PHP is already a ball of mud, imagine how much hairier that ball would be if all the important parts were wrapped up in classes and had no imperative counterparts. I still prefer the mysqli_ family of functions to the class and even to PDO, but of course I recommend PDO to anyone unfamiliar with anything else (and if they're not using MySQL).
Along with being a manifestation of the CGI model, I like how significantly more details of the request-response cycle are made explicit. When does the request end? When the PHP script is done. How can I make sure I do all my header-stuff before the first byte is sent? Use output buffering. What sort of request was sent, what data was sent? I can access it easily through the magic variables. phpinfo() is very useful.
I have even more but these are the important ones to me at this time. Again, some are features I wouldn't want in a general purpose language like Python or Clojure, but for web application development, where the constraints that force Erlang or Node or Java on the developer don't apply, PHP just works really well.
Posted on 2012-07-06 by Jach
Trackback URL: https://www.thejach.com/view/2012/7/so_php