Seven Reasons to Love PHP 7
Released in late 2015, PHP 7 was the first major PHP release in over a decade, skipping over the cancelled PHP 6 to provide a whole slew of modern updates. Here are some of our favorite features:
- Benchmark-Breaking Performance – A decade isn’t a lot of time in the large scope of things, but in terms of the internet, it’s eons. The PHP codebase was refactored to not only reduce memory consumption but to improve performance across the board. Now, expect your sites to run faster than ever (and, in most cases, twice as fast!).
- Uniform Variable Syntax – In previous versions of PHP, certain variable-variable expressions that “should” have worked (shouldn’t all of our code work the first time?) were classified as invalid. The PHP team has now made the language more consistent by improving the parser for a wide range of variable dereferences.
- Spaceship Operator – “Spaceship” is the cooler term for the Combined Comparison Operator, aka the three-way comparison operator. This makes chained comparisons far more concise than ever before (using individual operators of less than, equal, and greater than). This already exists in Perl and Ruby, making it easy to transition your logic from one language to another.
- CSPRNG – Most of us know RNG as our biggest enemy in gaming. CSPRNG, for PHP 7, has a radically different use: It’s a random number generator that makes passwords or password salt easy to generate. We suggest getting familiar with the functions random_int and random_bytes immediately.
- Scalar Type Hints – Parameter type hints have been in PHP for over a decade. PHP 7 introduces some new scalar types, specifically: int, float, string and bool. This makes it easier for the PHP runtime engine to validate the types of values passed to parameters and, thankfully, detect eventual programming mistakes.
- Anonymous Classes – Anonymous Classes allows users to create objects without the need to name them. This is ideal for simple, one-off objects (which should feel familiar to all the Java users out there) and allow for a type of nested class, the first time this is available in PHP. Here’s a great tutorial showing how to use them.
- Return Type Declarations – Code is (almost) always better when it’s easier to read. The new type Declarations not only makes code easy to to read but allows functions to return the expected data easier, following a similar rule for scalar type declarations. Kode Blog has a great breakdown that could help just about anybody.
PHP 7 is available across all Media Temple hosting solutions, including every Grid cluster. Grid customers whose accounts are set to use the “latest” versions of PHP will be automatically upgraded. For more information, click here.