Building a culture of objects in PHP
January 13th, 2006This is a follow up post to Why isn't PHP the natural successor to Java?
Joshua Eichorn (among others) notices that active record can't work as shown in the Zend Framework webcast. The syntax presented during the web cast is not possible in PHP because of inherited static methods are treated. Mike Naberezny notes the problem and suggests that it will end up getting fixed in PHP:
We’ve been working on the solution to the problem with statics on the C front, so eventually it will be solved there.
In the sitepoint thread Trouble in Zend Framework Land?, 33degrees smells vaporware:
I find it amusing that they did the webcast using that syntax, while there is currently no way of implementing it in PHP5. Makes you wonder how much code they'd actually written at that point.
Elizabeth Marie Smith does too and adds:
I find it rather annoying that they haven’t fixed the problem BEFORE now - after all, the bugs (marked bogus or wont fix because obviously the zend guys weren’t using php5 at that point if they didn’t see the problem until zend framework came along) the bugs/requests have been around for a LONG TIME
I look at this incident as an incredibly good omen. My optimism about Zend's PHP framework is not for the framework itself, but for what it means for OO support in PHP. In my book, the more developers that have commit access to both ZPF and to PHP, the better PHP 6 will be for me. I look at ZPF as an important step in building a culture of objects in the PHP community.
What?
In my previous post, I talked about how the leaders of the agile development culture seemed to be migrating from Java to Ruby with nary a glance at PHP. One of the reasons is that PHP lacks a culture of objects.
Support for object oriented constructs in PHP is relatively new, rough, and uneven. PHP competetors Ruby, Python, Java, and .NET all have OO class libraries, yet PHP does not. The classes and interfaces that PHP does have are not necessarily what I would hold up as paragons of modern OO design.
I can see why this would be the case. PHP is written in C. Being an expert in C programming does not necessarily make one an expert in object oriented programming (nor does it preclude it). My impression from reading the php-dev mailing list is that of a C culture rather than a object culture. (witness the goto vs exceptions debate.)
I'll save any critique of PHP's built in classes for OO for future blog posts. Instead, lets look at PHP's documentation. I regard PHP's online documentation as excellent. Its one of the factors that drew me to PHP in the first place. I especially like the comments system. Yet, go the the front page and search for one of the built in classes. Try "exception." Helpful? Did you know to switch the dropdown from the default functions option first? I'd like to link to the documentation for the Exception class. Where should I link? Classes are not first class citizens in the PHP manual as functions are.
Try searching for the 'getTraceAsString' method of the Exception class. I'd like to leave a comment about it, where should I go?
My purpose is not to run down PHP's support for objects. Merely to suggest that there is more work yet to be done for first class support.
Ok, so PHP doesn't exactly have a culture of objects. Who cares about objects?
To answer that, I want to explore the complex relationship between PHP and Zend. A good way to highlight the distinction is to look at the PHP usage numbers and the adoption rates for PHP 5. While web hosts account for the vast majority of the PHP usage numbers as reported, they have been slow to convert to PHP 5. On the other hand, Zend reports that 50% of their customers have adopted PHP 5, suggesting that Zend's customers are a bit different than the general PHP using population.
I think the PHP 5 adoption rates show that Zend's customers care about objects. I suspect that some of the object support in PHP 5 is a result of feedback from Zend's customers.
Zend is not a charity. I would imagine the ZPF project consumes a great number of resources and they are doing it for a reason. I think Zend's customers also care about frameworks. It sure looks to me like the ZPF project was triggered by Rails.
So somewhere in the ZPF project, they should be trying to do the same thing in rails and in ZPF and comparing the code. (if they don't there are a bunch of bloggers, me included, who will do it for them.) I'm sure their customers will do it too. Perhaps the Active Record syntax shown in the webcast was inspired from such a comparison? I think that in order to look good in these comparisons, some aspects of PHP's object support are going to have to be improved. Static inheritance won't be the last thing to get fixed.
Its is the zend framework effort thats going to put the finish on what PHP 5 started. I honestly believe that PHP 6 is going to end up a runaway success. (Is it still true that only the even numbered star trek moves are good?)
So if PHP doesn't exactly have the best reputation as an object oriented language, what can we do about it. Or specifically, what can Zend do about it?
Well, when Microsoft was being criticized for the lack of patterns in their PetStore example, what did the do? One, they fixed it. Two, they hired Martin Fowler's company to write about .net patterns. Ever notice how many .Net patterns there are in Martin Fowler's Patterns of Enterprise Application Architecture Book?
I'd like to see Zend hire a reputable object guru to help PHP turn around its object reputation. This should be someone who is known outside the PHP community, someone who has been going to OOPSLA for longer than PHP has existed. Someone who has a book on object oriented programming, articles, a blog, and who is an expert at teaching object oriented programming (10 years to be an expert). Writing and teaching help hone ones thoughts and this job requires a communicator.
To start, Zend can put this person to work both advising on ZPF and telling the world about ZPF. However, I would hope a longer term goal would be to apply some deep experience in coordinating and advising on the classes and interfaces that are going into the language itself.
I would hate to see the sales objection "php's functions are inconsistent" morph into "php's classes are inconsistent." Not only that, today's class and interface designs are going to be around a long time. Public refactoring is not a good in a language class library or in a widely used framework. Witness the slow adoption of PHP 5 and the problems with reference changes in 4.4, 5.0.5. Deep experience can help get a better design at the outset.
I for one welcome our new object oriented overlords. ![]()
January 13th, 2006 at 2:43 am
Nice article! Gang of Four, where are you? :]
January 13th, 2006 at 1:38 pm
Great article!
I'd like to see Zend hire a reputable object guru to help PHP turn around its object reputation. This should be someone who is known outside the PHP community, someone who has been going to OOPSLA for longer than PHP has existed. Someone who has a book on object oriented programming, articles, a blog, and who is an expert at teaching object oriented programming (10 years to be an expert).
Yeah! I nominate Bruce Eckel.
January 13th, 2006 at 6:44 pm
Hi Jeff.
Darn it, I was going to talk about object culture in PHP at the upcoming Florida gig, and you beat me to it :(.
yours, Marcus
January 23rd, 2006 at 10:25 am
In talking about....
"...how the leaders of the agile development culture seemed to be migrating from Java to Ruby with nary a glance at PHP."
...the next comment seems strange.
"I can see why this would be the case. PHP is written in C."
Especially strange when you consider that Ruby is written in C (as well as Python). Perhaps it's more correct to say that the PHP developers are not from or of a culture that OO centric.
I'd hate to see someone accept that statement without question.
Cheers
May 18th, 2006 at 11:24 pm
Framework or not.Are we going to be java like inhertiable like lang.java.xxx or whatever or like .net framework library.PHp are easy to code but the main problem is they don't have fix idea when developing software.Like vb at less they object.movenext but in php there are actually no way paging via oop style vb.So i have to create my own class just for pagenation.One more thing about class and object.Memory when use in the same function like you have to for($i=0;$i++) at the difrent function the data come back eventhought the value have been protected.Should be suppose.