What’s new in php5.3?
As the release of php 5.3 is nigh, let’s take a look and see what the php guys have messed up erm.. improved this time. The world of the interpreted langues had passed by php a long time ago, can this old dog learn a few new tricks? I hope so. I work with php on a daily basis, and I don’t like it – its current state. Anyone who have written some real world ruby or python code can see what I mean – php just “sucks”, it feels heavy and bound, sometimes it’s just a pain in the ass. This of course doesn’t mean php isn’t one of the best platforms for web development… yes, I say platform, not a language. Anyway, let’s see what we’ve got here.
First, we get namespaces
Aye, say goodbye to lengthy, domain-prefixed function names. We won’t need to say couchdb_fetch_dbs() again, instead we’ll write namespace CouchDb and then CouchDb::fetch_dbs() woot! This can also reduce class name clashes. Yes, namespaces can be embedded, so we can have Oh::My::God::this_is::deep. Wait, wait. Are we sure Oh::My::God::this_is::deep::iamanicefunction_whydontyoucallme() is a step in the right direction? The ‘use’ keyword comes to convince us that it is: as in any decent, namespace-supporting language, we can ‘include’ any part of the namespace (watch out for clashes though). So just say use Oh::My::God and then God::this_is::deep::iamanicefunction_whydontyoucallme() and there you go. You can even import single classes. I mentioned clashes above – what can we do about them? Hey, php seems to get more intelligent this time, and it supports namespace aliases. Cool. We now can say use NamespaceOne::User as FirstUserClass and use NamespaceTwo::User as SecondUserClass. Namespaces aren’t for classes only! We can define functions inside, too. Also, we have the global namespace – ::global_func() , which is useful if we want to call a global function from inside a namespace which has a function with the same name.
So, a quick summary:
- Namespaces of depth
- Importing namespaces/classes
- Namespace aliases
- Namespaces aren’t limited to classes, functions also work.
- Use the global namespace, Luke!
Then we have late static binding
What the hell is that?! Consider a simple example of overriding the parent’s static method:
class IamyourfatherLuke {
static public function SayMyName($whoami) {
self::do_the_speaking($whoami);
}
static public function do_the_speaking($what) {
echo "Darth Vader says: {$what}\n";
}
}
class ThisisLuke extends IamyourfatherLuke {
static public function do_the_speaking($what) {
echo "Luke says: {$what}\n";
}
}
ThisisLuke::SayMyName("hello Leia");
Now, what will this print? Easy: “Darth Vader says: hello Leia”. Wait, what? Hey, I’ve overridden the ‘do_the_speaking’ method! Aye, you did, but forgot about that tricky little ‘self’ prefix in the original class! ‘self’ resolves to the exact class the reference is used in. And it’s used in the parent class. What if you really want to override such things? Well, firs, wait for php 5.3, and then say static::do_the_speaking($whoami);
We also get a native mysql driver
Of course we will still be able to use the good old libmysql based extension, but why not try a zend-optimized, php specific one which at least will obey the php setting regarding maximum memory size and also use the zend engine’s memory management system?
Oh, yes, and class constants
Need I say anything about this? This is clearly a gem in the pavement to better system design.
SQLite3 support built in
Nice. Perfect for starting small and even sufficient for some mid-scale stuff.
My personal favorite: E_ALL now includes E_STRICT.
Nothing compares to the beauty of conforming unspoken specifications. Also, E_STRICT has been broken apart to E_STRICT and E_DEPRECATED. Nice.
I can hardly wait for more goodness, like anonymous functions and closures, but sadly that’s a long way from here. PHP seems to be making baby steps. Actually, baby steps lagging years behind.
9 comments
Trackbacks/Pingbacks
- ??????? » [Web] ???? - [...] What’s new in php5.3? [...]
Leave a Reply
Additional comments powered by BackType


Thanks. It was very helpful. Can’t wait to install PHP 5.3 and run it for a spin.
[Reply]
Hmmm… cut ‘em some slack, they’re coming along. : )
[Reply]
ochronus Reply:
May 13th, 2009 at 06:18
Yep, sure they do, in a few years they’ll be where ruby was a few years ago ;) Ok, just kidding, it’s not fair comparing two different animals.
[Reply]
Thanks to PHP 5.3 late-static binding and closures my friend Kien and I have improved upon an earlier version of an ORM that he had written prior to PHP 5.3. The ActiveRecord we have created is inspired by Ruby on Rails and we have tried to maintain their conventions while deviating mainly because of convenience or necessity.
Take a look here:
http://www.derivante.com/2009/05/14/php-activerecord-with-php-53/
[Reply]
Wow, this seems really nice! Congratulations! :) @Jacques Fuentes
[Reply]
Thanks. Stay tuned for updates. Like I said in the post, we should have this on launchpad soon with a website to-boot!
[Reply]
Dude.
I have read now two articles on your site.
In both articles concerning PHP you take a small innate example of something completely unrealistic to the real world and twist it into some asinine argument as to why PHP sucks…
Fair enough you LOOOOOOOOVVVVVEEEE RUBY or python or whatever…
Then please get out of the PHP business, let PHP professionals do their job.
Someday when RUBY actually gets used to do something more than make a blog in 5 minutes maybe you’ll find a purpose in life.
Sorry but you really come off as one of those kids in a class who asks completely moronic questions just to waste the teacher’s and other student’s time.
Either do PHP or don’t do PHP. Complaining about it won’t help anything.
[Reply]
ochronus Reply:
May 20th, 2009 at 10:30
1. Actually this array indexing thing came to light in a live system so I wouldn’t consider it unrealistic.
2. The fact that I complain about certain ‘features’ of PHP does not mean that I should stop using it. So your point of view is that either hype something or don’t use it at all? A bit of black-or-white, don’t you think? But of course you have the right to state your opinion, just as I do – that’s what this blog post is about. So stop complaining about my posts and stop reading them ;)) get the point?
3. Not doing php is not an option since losing my job would have some harsh consequences.
4. I also use ruby on a daily basis for work – trust me, a language is not only about web :) You CAN do many more things with ruby than rails. Rails is just a framework written in ruby, it’s not ruby itself.
Anyway, thanks for expressing your opinion.
[Reply]
@Rob
Dude.
You’re basically saying noone forces me to stick with PHP, if I feel unsatisfied, I should not comment on it, just move on silently.
So, noone forces you to read my posts, if you feel unsatisfied, don’t comment, just move on silently.
See, you’re doing the exact same thing you’re accusing me of. What’s the difference in the attitude?
Of course the same urge is present in you – for some reason my posts pissed you off, just like php’s little clever ‘feature’ pissed me off. We are humans, we like to rant a bit about what’s bugging us. What’s wrong with it?
[Reply]