Programming Web Development

PHP 5.4 And Short Syntax

I’m actually pretty excited about PHP 5.4’s release. I still manage to write a fair amount of PHP these days.

I suspect it will be quite some time until I have enough PHP 5.4 targets to utilize some of the newer features like Traits and the short array syntax, but that’s OK. Performance and memory improvements are always welcome. I doubt I’ll touch the built in web server much. It seems to only be intended for testing, and I never really ran across PHP without Apache (except when I didn’t want it in which case CLI is what I wanted).

One slight disappointment is that there is a short array syntax, but no short object syntax. I guess you could always use casting to make it happen like this:

$obj = (object) array(‘foo’ => ‘bar’);
$obj = (object) [‘foo’=>‘bla’, ‘bar’=>2]; // PHP 5.4+

But that still isn’t ideal. I’d prefer to see:

$obj = {‘foo’=>‘bla’, ‘bar’=>2};

Maybe next time around.

Leave a Reply

Your email address will not be published. Required fields are marked *