As you probably have noticed, PHP 5.4 is around the corner. As far, there’s Release Candidate 6 available and final release is a matter of weeks. Let’s have a look at new features, that will make PHPers live easier.

Traits

The major change is traits implementation. Traits aims to reuse code in horizontal way. It’s well known mechanizm in languages like Scala or Ruby (mixins). Traits allow you to omit lack of multiple inheritance (like in C++) by “using” methods from other parts of code. Example will be the best description:

Array dereference and short syntax

Like in Ruby, Python or JavaScript, you can now declare arrays in handy way, by surrounding elements separated by comas with square brackets. But what is better, there’s possible to call array element directly after function call.

Callable type hinting

After introducing closures in PHP 5.3 there wasn’t good way to type hint a callback type. There were internal \Closure class, but documentations said to not rely on it, because its behavior may change. Now we have Callable type, which can be used effectively to protect our method signatures.

Summary

Above I present only few of most exciting features to me. There are a lot more, like a built-in development webserver or file upload progress. To better get to know with them – build PHP 5.4 on your own machine and play with it!