Initial PHP 5.5 support in PhpStorm
With the Early Access Program for PhpStorm 7, we’ve added initial support for PHP 5.5. When working in a project making use of the new PHP 5.5 language constructs, we can switch to the PHP 5.5 language level in PhpStorm and get full code completion and syntax checking support from the IDE.
Let’s have a look at these new language features!
Generators
Generators provide an easy and readable way for implementing iterators. Take a foreach: the iteration will be run for every value that was returned with the new yield keyword.
The following class can run a closure on every element of an array and “yields” the mapped value:
Some additional examples are available on the RFC page.
Finally!
The finally keyword allows for cleaning up after an exception has been thrown. For example, when using a database connection we may end up with an Exception thrown by a called function. Using the finally keyword, we can gracefully close this connection regardless of the fact an exception occured or not.
Using list in foreach
A nice and handy new feature in PHP 5.5 is the ability to use list() in a foreach loop. Take the following code snippet:
Using PHP 5.5 we are able to transform each array entry into a list of variables which we can use in our code. Additionally, PhpStorm provides syntax highlighting as well as code completion!
Class name resolution as scalar
Reflection is great, and being able to instantiate a class from a string variable is even better. But why is that we always tend to make typos in strings… Using the ClassName::class syntax, we can get the class name as a string with full IDE support.
Other enhancements
A number of other enhancements for PHP 5.5 language features have been added. PhpStorm now supports empty() and isset() on expressions. It can even resolve const array/string dereferencing, like for instance providing the output of str_repeat(“foobar”[3], 3)[1]”).
Give PhpStorm 7 EAP and PHP 5.5 a try and let us hear your thoughts in the issue tracker, comments below or in our forums!
Develop with pleasure!
– JetBrains PhpStorm Team