Tuesday 30 June 2015

PHP 7 Faster Performance and New Features

PHP 7 Faster Performance and New Features

As the PHP 7 release date is fixed and its November 2015. PHP is coming with very Fast Performance and many New features. All the new changes make PHP stronger.
According to the reviews, running  drupal 7.27 on PHP 7 is 4.23 percent faster than running it on PHP 5.6, that number rises to 25 percent faster for those running earlier builds of the in-development Drupal 8 release.
So, the long story short is that PHP 7 will be a significant boost over PHP 5.6.
Given that it’s still early days for PHP 7 and the final release is still months away, I suspect there will be further innovations and improvements. The net result is that we can all expect to win as PHP applications will be the big winners overall.
Some of the new exciting features of PHP 7 here :
1.     Anonymous classes  :  (

Anonymous classes enable you to make your code more concise. They allow you to create a class and a new instance of it in a single expression. They are like local classes except that they do not have a name. They use the existing class syntax, with the name missing:

Syntax : New class (arguments) {definition}



Example :

var_dump(new class($i) {
    public function __construct($i) {
        $this->i = $i;
    }
});
2.     Null coalesce operator:

A Student:


The coalesce, or ??, operator is added, which returns the result of its first operand if it exists and is not NULL, or else its second operand. This means the $_GET[‘mykey’] ?? “” is completely safe and will not raise an E_NOTICE.
Example :

// Fetches the request parameter user and results in 'nobody' if it doesn't exist
$username = $_GET['user'] ?? 'nobody';

3.     Abstract syntax tree :

A complete change to the way in which PHP is interpreted allowing for a greater amount of flexibility and the possible introduction of a just in time compiler in the future. Without a JIT compiler, PHP 7 is already about twice as fast as PHP5 and on par with Facebook’s PHP interpreter (which is JIT compiled). Adding a JIT compiler would make PHP7 even faster.
4.     Fatal Errors replaced with Exceptions :

A Person:



The ability to replace fatal errors with exceptions so you can catch them instead of PHP just dying is an interesting new feature.
Example :

function call_method($obj) {
     $obj->method();
}

try {
     call_method(null);
} catch (EngineException $e) {
     echo "Exception: {$e->getMessage()}\n";
}

5.     Return types :
Many developers would like to be able to declare the return type of a function. PHP 7 will allow developers to declare what kind of return type a function is expected to have, similar to argument Type Hints.
In addition, argument type hints and the new return type declarations now support new scalar types, allowing developers to declare that they are expectine strings, floats, ints to be returned.

 function increment(int $a): int
 {
  return $a + 1.0; // strictly type checked return
 }


No comments:

Post a Comment