Everything You Need to Know About PHP 7 Features It’s been 11 years since the inaugural PHP release. With the next version on the horizon, here are the PHP 7 features we can’t wait to get our hands on. It’s been 11 years since the inaugural PHP release. And with access to the PHP 7 features in the latest edition upon us, 2015 and 2016 are expected to be big years for one of the world’s most popular programming languages. On November 26, the PHP development team announced the thirteenth pre-release of PHP 7.0.0. From security issue fixes to new capabilities, there’s a lot to get excited about in the latest PHP overhaul. Here’s what you need to know for the big changeover. PHP 7 updates Performance. It’s top-of-mind for any language update. Here’s how the PHP 7 features in the latest release will stand out. phpng. PHP Next Generation has been merged with the master branch of PHP improving overall performance. PHP 7 will be able to manage twice as many WordPress requests per second. Speed. PHP 7 will be twice as fast as PHP 5.6 now equipped with a new version of the core scripting engine for PHP — Zend Engine. Applications will run much faster and smoother than before. Memory. The latest release will use approximately two thirds of the memory it previously did. That means three times the throughput as PHP 5.6. Support. PHP 7 will offer consistent 64-bit support. Exceptions will be handled differently Script that would result in a fatal error in past versions of PHP will now be handled as exceptions. Software architects from the PHP/LAMP team break down how this will effect the user experience. Prior to PHP 7, fatal errors and recoverable errors would halt the script execution without throwing an exception. This means that these errors could not be handled like exceptions and presented in any desirable way to the user. In PHP 7, if the script reaches a fatal error, it throws an error exception, which can be handled like a regular exception with the try/catch block and execute the finally block afterwards (if present). This new method allows us to present most fatal and recoverable errors to the users, the way we want. Some type of fatal errors will still halt script execution (like running out of memory, for example). Breaks in backwards compatibility with new PHP 7 features It will be especially important to avoid or rewrite deprecated code with the recommended PHP tag. Our architects compiled the compatibility changes with the potential to be most trouble. Changes to error and exception handling. Most of the applications use some kind of error handling. In this case, there might be cases where those custom handlers won’t be triggered because exceptions will be thrown. Changes to the handling of indirect variables, properties, and methods. This update is important for most of the applications and needs to be considered with priority. Empty list() assignments have been removed. This is also important to keep in mind, because empty lists are usually used. Changes to Division By Zero. There might be cases where an error will be thrown instead of a warning. This will affect the production environment where warnings are suppressed. u{ may cause errors. Literal u{ which is commonly used followed by an invalid sequence will cause a fatal error. The leading backslash must be escaped. What was removed from PHP? GD Type1 functions changes ASP and script PHP tags Calls from incompatible context $HTTP_RAW_POST_DATA # comments in INI files New capabilities in PHP 7 Beyond grooming deprecated functionality out of PHP 7, the team working on PHP 7 included a host of new functionality. Closure functions. With Closure functions, we are able to use benefits from functional programming. We can use arrow functions (anonymous functions), and we have a new keyword yield. CSPRNG. With CSPRNG, we are able to generate crypto-strong random integers and bytes. Error handling and logging. We can create a custom errors, we can add a log of errors and we can error stack trace. Generators. These introduce a new methods for the iteration of values, function, etc. The heart of a generator function is the yield keyword. In its simplest form, a yield statement looks much like a return statement, except that instead of stopping execution of the function and returning, yield instead provides a value to the code looping over the generator and pauses execution of the generator function. Matching. PCRE Functions::preg_replace_callback_array with this function we can run arrow functions, when we have matching. Specification. With ZipArchive, developers can specify compression index. Deflate. Zlib Compression offers four new functions for working with deflate. Over the moon about the Spaceship Operator Much to-do has been made about the addition of the Spaceship Operator. And for good reason. The three-way comparison operator already exists in Groovy, Perl and Ruby. It’s finally made it’s way to PHP. Used for combined comparisons, the Spaceship Operator will enable sorting lexographically and will also make ordering callbacks with usort() easier. Operators like Spaceship bring PHP closer to higher end development languages like C#. Check for errors in the code base with the following before the PHP 7 rollout php_check_syntax can be used for checking of PHP syntax. (<= PHP 5.0.4) Example: php -l somefile.php Output: PHP Parse error: unexpected T_STRING in /tmp/somefile.php on line 81 If we want to do it in the code, we can run the command with shell_exec(‘php -l somefile.php’) Have a question about a PHP project? Let’s talk. MentorMate has built over 30 projects using PHP. We work with several frameworks including Laravel, Symfony 1&2, Zend Framework, Phalcon and CodeIgniter. We have built a wide range of solutions from backend API’s, CRM systems and CMS systems to ecommerce and marketing websites. Share Share on Facebook Share on LinkedIn Share on Twitter