PHP 7

The name is PHP 7.

 

Who Spearheaded the Development of PHP 7?

 

Rasmus Lerdorf credits three developers with driving PHP 7 forward: Dmitry Stogov, from Zend; Xinchen Hui, from Lianjia Technologies; and Nikita Popov, a computer science/physics student in Berlin. These three developers created an experimental branch of PHP that they originally called PHP Next Generation, often abbreviated as PHPNG.

 

Why PHP 7 is created?

 

PHP 7 is the PHP community’s response to Facebook’s HHVM (HipHop Virtual Machine). Early announcements of the launch of PHP 7 claimed that it would offer better than 100 percent performance improvements over the previous version of the language, PHP 5. PHP 7 has been focused on performance and memory utilization. It  claimed that it would offer better than 100 percent performance improvements over the previous version of the language, PHP 5.

post1post2

 

So whats new in PHP 7

 

Null coalescing operator

<?php
// Fetches the value of $_GET['user'] and returns 'nobody'
// if it does not exist.
$username = $_GET['user'] ?? 'nobody';
// This is equivalent to:
$username = isset($_GET['user']) ? $_GET['user'] : 'nobody';

Spaceship Operator

<?php
// Integers
echo 1 <=> 2; // -1
echo 1 <=> 1; // 0
echo 2 <=> 1; // 1

  • If 1 is less than 2, this expression outputs -1
  • If 1 is equal to 1, this expression outputs 0
  • If 2 is greater than 1, this expression outputs 1

Constant arrays using define()

<?php
define('ANIMALS', [
    'dog',
    'cat',
    'bird'
]);

echo ANIMALS[1]; // outputs "cat"

Filtered unserialize()

<?php 
// converts all objects into __PHP_Incomplete_Class object 
$data = unserialize($foo, ["allowed_classes" => false]);

// converts all objects into __PHP_Incomplete_Class object except those of MyClass and MyClass2
$data = unserialize($foo, ["allowed_classes" => ["MyClass", "MyClass2"]]);

// default behaviour (same as omitting the second argument) that accepts all classes
$data = unserialize($foo, ["allowed_classes" => true]);

Return type declarations

<?php
function arraysSum(array ...$arrays): array
{
    return array_map(function(array $array): int {
        return array_sum($array);
    }, $arrays);
}

print_r(arraysSum([1,2,3], [4,5,6], [7,8,9]));
Code above will output:
Array
(
    [0] => 6
    [1] => 15
    [2] => 24
)

Reference:
http://php.net/manual/en/migration70.new-features.php