I’m an advocate of tidy, well commented code, and something that has bugged me for a little while was the messiness of the ternary operator (?:) in PHP. With the introduction of PHP 5.3.0, we can now miss out the duplication messiness of using the ternary operator for existance checks for example. Instead of:
$value = $a_value ? $a_value : $b_value;
We can now simply do:
$value = $a_value ?: $b_value;
It goes without saying that one should still not nest ternary operators as they become messy and extremely difficult to understand, even with good commenting. Consider an if/elseif/else or switch instead.
There are a few other things in PHP 5.3.0 that I’m looking forward to as well, one of which is the bundling of ext/phar which is really rather cool.
There are other dubious things, which are covered (and argued) in great detail elsewhere such as the goto operator and the introduction of namespaces…
October 12th, 2009 at 9:58 am
Awesome, I did not know about this! I’m still coding for 5.2 though
October 12th, 2009 at 10:30 am
Aye me too :/