Category: CommunityWhat Can We Expect From PHP 7?

Share this post...Tweet about this on TwitterShare on Google+0Share on Facebook0

What To Expect From PHP7Love it or hate it — and there are plenty of developers on both sides of that potential flamewar — it’s undeniable that PHP has become an essential underpinning of the modern web. Many of the web’s most important applications and sites are based on PHP: WordPress, Magento, Facebook, and of course, InterWorx, to name just a small fraction. Back in 1995, when what was to become PHP was first released, its creator Rasmus Lerdorf thought of is as a simple C API that made it easier to carry out some common web development tasks. Twenty years later, what was once quaintly known as Personal Home Page Tools, is seeing a renaissance thanks to tools like Composer.

This year — in October if all goes to plan — PHP will get its first major version bump since 2004 when PHP 5 was released, although PHP 5’s minor releases have seen many great new features added over the years. PHP 7 (there will be no PHP 6) incorporates thousands of changes, but I’d like to focus on three headline features that will make a significant difference to the day-to-day experience of PHP developers and their users.

Performance Enhancements

This is the big one. PHP 7 will be based on PHPNG, which was a version of PHP based on a refactored Zend Engine. The focus was on performance and memory improvements, and testing shows that the work has paid off handsomely.

Performance hikes of between 25% and 70% have been seen. As an example, executing WordPress’ homepage on earlier versions of WordPress took around 9.5 billion CPU instructions. PHP 7 does it in approximately 2.5 billion — a saving of more than 70%. The exact improvements depend on the benchmark and specific application environment, but in many applications PHP 7 has been shown to be on par with Facebook’s HHVM.

Scalar Type Hints

Scalar type hints allow developers to specify the types of values that can be used in function parameters and return values. They help developers avoid a specific set of programming errors that occur when the wrong value type is passed to a function. Previously, using the wrong value would not necessarily lead to an error and could result in unpredictable behavior in applications. Scalar type hints make it “easier [for developers] to reason about code”.

If you want to know more about scalar type hints, Jose Luis Laso has written an excellent summary.

The Spaceship Operator

PHP 7 gets a new comparison operator. The <=> operator returns a value based on the results of a comparison that indicates how the operands differ. If the left operand is greater, it returns 1. If the right is greater, it returns -1. And if they are equal, it returns 1.

The spaceship operator is especially useful for sorting functions, allowing developers to quickly make comparisons they would previously have to have written more extensive code to carry out.

In addition to the three changes we’ve discussed PHP 7 also includes another new operator: the Null Coalesce Operator; improvements to generators, and group use declarations.

Image: Flickr/Kovah.de

PHP
Jul 2, 2015, 12:46 pmBy: Corey Northcutt (0) Comments

Leave a Reply
Surround code blocks with <pre>code</pre>

Your email address will not be published.

Newsletter

Sign up to receive periodic InterWorx news, updates and promos!

New Comments

Current Poll

  • This field is for validation purposes and should be left unchanged.

Forum Posts