I’ve come around again to looking at PHP5 for a few projects. I started with some small self contained pieces that could be easily tested on their own. To be fair I wrote this code to only work with PHP5, trying to take full advantage of the new features. I quickly developed two complaints:
-
NO MULTIPLE INHERITANCE?
I like being able to re-use code, multiple inheritance should be a no brainer here. After digging around Google trying to figure why they would leave this out of PHP5 the most common excuse seems to be that it might be confusing for some people. After all, what if method foo() exists in multiple parents? Big whoop, establish a rule on how to deal with that and move on. Perl’s solution to this I believe is left to right, with ways to override that if needed. Continuing the argument against multiple inheritance it has been said in order to implement you can use interfaces. This is completely bogus! Interfaces have a use, multiple inheritance isn’t it. How can you have code re-use in an interface since it is specifically there not to implement code? -
EXCEPTIONS DON’T HANDLE ERRORS?
After getting over the feeling that PHP5 is trying to impress Java, I’ve been happy with having exceptions in PHP5. Unfortunately I was foolish enough to assume that normal errors in PHP would throw exceptions that I would be able to easily catch. Bzzzt, wrong! Turns out that exceptions are basically a ‘userland’ sort of thing, the system will still chuck errors the way PHP4 did. To get around this I wrote a simple error handling function that simple took an error and threw an exception using the error information. This adds another layer of code calling set_error_handler() and restore_error_handler() before and after a try and catch block that might cause a PHP error. Although I couldn’t find any documentation to confirm this, I suspect this was done in an effort to try and preserve backwards compatibility with PHP4. I would have rather seen additional knob that would use set_exception_handler() or something to make PHP4 code happy.
I generally try not to run around ranting against this and that, I just feel strongly that PHP5 missed out on some very useful and very important steps. I’m still a big fan of PHP, I consider it one of the best languages for web apps. Unfortunately that doesn’t keep me from being disappointed in what could have been for PHP5.