Why I Like PHP revisited

Original post provide by PHP Everywhere - By John Lim

A quick response to all the “PHP sucks” postings listed in PHP Developer that were sparked by Tim Bray’s original PHP rant.

Yawn… been there, said it before.

But given that I like a good controversy, and our memories are short, here’s my view again:

  • When I first coded in PHP, I treated PHP as a better Javascript that I could use on the server-side. True Javascript isn’t perfect either but we all use it for designing user interfaces and web apps. And if we can accept Javascript (an admitted hack by its designer) as a language for enterprise use, then it seemed obvious to me that there was no reason why PHP isn’t suitable for the Enterprise: PHP has a familiar C-style syntax, it scales, PHP has builtin support for the template pattern (the very heart of MVC if you like it), you can write modular code, use inheritance, and code in teams.

    It’s just some people don’t like it and snipe at the edges.

  • PHP is, and not by some twist of fate, good for developing web apps. Allowing HTML and PHP to intermingle in a .php or .inc template is pretty good. It maps to a very natural way of working. So the success of ASP, JSP and PHP are not really by accident. In contrast, you can write pretty awful Python or Java code to output HTML using print or java.io if you don’t use a template pattern, which is built into PHP!

    There have been abuses of the template language, notably PHP Nuke (and not only by others, i’ve been guilty too), driving serious programmers to scoff at PHP. I think they need to do more and read less.

    Take my example: when I first started trying out PHP, I didn’t worry about all the code abuse I saw out there. I’ve coded in Perl, and seen the same shit before. What I did to try PHP was write some web pages to see how easy coding was, wrote some OOP classes (the start of ADOdb), then benchmarked the results. Based on my checklist, i knew it was good enough, and that was in early 2000:

    1. Support for classes and modular code: yes.
    2. Easy to code: yes.
    3. Easy to teach and plentiful docs: yes.
    4. Templates: yes (the first release of Smarty was the clincher).
    5. Speed: faster than ASP based on my benchmarks.
    6. Scalable: near linear scalability based on my apache-bench tests.
    7. Customizable: err, its open source…
    8. Platform agnostic, no anti-Microsoft idealogy: yes, support for Windows not an after-thought.
    9. Large PHP community and high potential for growth: yes and yes.

  • PHP also has a great library of functions for string manipulation, database access, graphics manipulation, and for accessing weird but useful external software such as memcached. Does PHP have library inconsistencies? Yes, probably inevitable given the enormous size of the standard library of extensions and the open source nature of its development. Are the inconsistencies important? Probably not, unless you don’t want to use PHP.

  • PHP breaks down the ivory towers (thank god!) Unlike Java or Python, you can have a team with different skills using PHP. The hardcore programmers build the core libraries, and the web designers and more sociable programmers working on the user interfaces, all coding in PHP.
  • PHP is mainly a string processing language. That makes it really good for manipulating HTML. Features like “0″ == “” and weak-typing work well for text processing(see note 1). Some people have said that PHP’s Unicode support is not fantastic. Agreed, there is not enough native Unicode support outside UTF-8; but despite that PHP has been a fantastic success even in countries using double-byte languages. That cannot be by accident or due to ignorance.
  • The only real PHP gotcha is that PHP cannot do everything. PHP is good for web app user interfaces and business rules, and as a shell scripting replacement. If you look at big PHP apps, the stable core is written in another language, C/C++ (Yahoo), or Java (Ning), or PL/SQL (my company). In a sense, all the interesting techie stuff in PHP is happening at the C level, in the PHP extensions: in pdo, gd, oci8, mysqli, etc. Everything else, PEAR, Smarty, Drupal, Sympony, ADOdb, PHPLib etc, is just fluff :)


    PS: But if you’re really good, you can build 90% of your enterprise app in PHP. See Flickr’s architecture (pdf).

  • If you are looking for a better Java or its replacement, sorry it hasn’t been invented yet. PHP doesn’t come close. I do think that Jython comes close, but it lacks the Java-style syntax required to make it really popular, and there’s no one (that I know) speeding up Jython the way Jim Huginin is tuning IronPython for .NET.

Note 1: You use strlen($str) == 0 to check for empty strings - that’s a fundamental string-matching pattern in PHP.

Also see Harry Fuecks pro-PHP rant.

Previous Articles:
Inserting Multiple Rows With One Database Call Using PHP And Oracle Collections
How to use Oracle collections to improve the efficiency of PHP scripts that feature multi-row inserts
Is PHP4 The New Perl?
I think PHP5 is more attractive to people who want to code with rigor. So is PHP4 perl for the web? PHP can be used or abused, just like perl. The abuse is what makes it popular :)
Yahoo! Goodies: UI Library And Design Patterns
Useful, but don't be misled. The User Interface Library includes libraries for drag and drop, animation and othehr interesting stuff under a BSD license. Widgets provided include Calendar, Slider and Tree View. The widgets don't seem particularly interesting (there are good alternatives out there), but the attractive thing about these libraries are that they have probably been thoroughly tested on more browsers than I could possibly test on.
PHP Life : The Oracle
After a short break the PHP Life team are back. In this strip we look at the Zend/Oracle deal. If Oracle do buy-out Zend then let's hope things fare better for the Zend staff than Oracle staff at the moment!
PHP @ FrOSCon: Call For Papers
The Free and Open Source Conference (FrOSCon) 2008 is a two-day conference on free software and open source. It will take place on August, 23th and 24th 2008 in Sankt Augustin near Bonn, Germany.The PHP Usergroups Dortmund, Köln/Bonn and Hamburg are cooperatively organizing the PHP track as a sub-conference of the FrOSCon.
More Articles:
PHP Compilers
I am excited about all these implementations. Most computationally intensive compiler benchmarks have shown a 5-10 times speedup over mod_php. Perhaps it is only a matter of time before we see a JIT compiler for PHP to Intel opcodes, built into mod_php...
Paris Forum 2007 : Call For Papers
This email must contain the following information: namecompany if applicablea short (4-6 sentences) biography about your PHP experiencecomplete name and addressinclude photo for each speaker (JPEG format)Sessions will typically be 45 minutes long followed by a 10 minutes Q&A session.You are allowed to submit several proposals.
Steve Yegge On Strong And Weakly Typed Languages
At this juncture, I think enforced static typing (e.g. what you find in Java, C++, OCaml, Ada, etc.) is detrimental to progress and flexibility. I also think that a complete lack of support for it (e.g. what you find in Ruby and today's Python) is problematic for being able to selectively tighten up systems as their usage patterns become established.
Using Oracle's Built-in Security Features With PHP
How to take advantage of Oracle's native security features to improve the security of your PHP Web applications
The PHP.net Google Summer Of Code
Seven students will "flip bits instead of burgers" this summer: Mentored by Michael Wallner, Hannes Magnusson will work on LiveDocs, which is a "tool to display DocBook XML files in a web browser on the fly, without the need of building all HTML target files first".

Leave a Reply