A blog about software development best practices, how-tos, and tips from practitioners.

A Programmer's View Of PHP 7

PHP got the developer community talking when it announced PHP 7. Now that PHP 7 has finally been released, there’s little that is keeping the PHP developer community from shooting rockets! PHP 7 can quite easily pass off as one of the most important and significant PHP releases since the release of PHP 5 in 2004. PHP 7 promised major performance improvements, reduced memory consumption and new features to make great apps. So did PHP7 manage to deliver on these promises? Here’s a programmer’s view -


Performance Improvement:

The one thing that PHP 7 shouts from the rooftops is ‘performance improvements’. According to Zend Technologies, the company that spearheaded the PHP Next-Gen (PHPNG) project on which PHP 7 is modelled, promised 50 to 200 percent performance improvements on real world apps. According to PHP creator Rasmus Lerdorf, “Most code will run twice as fast as before, with some caveats." While this might not help those who spend a lot of time with databases, for most people especially large companies, this improvement means that they can turn off half their data centers! What’s most amazing about PHP 7 is that all the PHP-based websites will be running twice as fast without making ‘any’ change to the underlying software code. PHP 7 was able to achieve this since they have optimized the internals while writing the code and made them smaller.

PHP 7 can also handle 60% more requests as compared to the previous versions and can be especially helpful for the Magento applications which can probably now handle double the transaction with same hardware with PHP 7.

Error Handling:

PHP 7 makes error handling exceptionally easier for developers. Instead of emitting standard PHP errors, the PHP engine will now emit exceptions by catching all ‘Throwables’ which has changed from the previous versions and ensures that new exceptions do not get caught up legacy catch-all statements (catch (\Exception $e) { }). Further, PHP 7 also enables reduction of errors while coding as it declares expected return type from function. All the changes incorporated in error handling ensure that most of the previously fatal errors can now be managed with ease and grace.

Spaceship Operators:

PHP 7 has introduced the ‘Spaceship Operator’ which is very similar to a TIE fighter. The Spaceship operator is a Combined Comparison Operator that assists in comparing two variables but instead of returning either true or false it,instead, returns -1, 0 or 1. The 0 represents equality while 1 represents greater than and -1 represents less than. This helps immensely to parse arrays that need sorting.

Group Use Declarations:

Perhaps one of the coolest improvements in PHP 7, Group Use Declarations make it much easier to import constants, classes and functions in a concise and extremely readable manner. They give the ability to import ‘multiple structures from a common namespace’ and make it easier to identify if these entities belong to the same module. Since there is a reduction in the effort of calling classes in every file, the number of lines of code will also reduce.

Among the other new features is the 'Unicode Code point Escape Syntax' that facilitates easier string manipulation and makes things like a string or printing emoticons using Unicode characters much easier.

While almost everything looks great with the shiny new PHP 7, developers wanting to migrate from PHP 5x to PHP 7 with MySQL PHP API will not be able to do so. This is because the MySQL PHP API extension has been replaced with MySQLi since the latter has better performance. However, this will not be a problem for those applications where MySQLi and PDO are used to connect to the DB. Another problem could arise because of the Uniform Variable Syntax that PHP 7 extends, which might lead to possible errors if variable declarations are done in styles adopted in earlier versions.

This being said the new and improved PHP 7 is definitely kicking up a storm in the developer circle. According to Zend, when PHPNG was first published, the the WordPress homepage required approx. 9.4 billion CPU instructions to execute.  As of now – it requires only 2.6 billion – that's 72% less!. We are excited to see what numbers we are going to hit with PHP 7 with the open sourced PHPNG merged with it.


Like what you just read? Get Latest content delivered straight to your inbox.

Drop Your Comment