package info

 
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get remove php7.0
sudo apt-get install php7.1
sudo apt-get --purge autoremove
 
#  to mantain PHP5 along with PHP7-cli:
sudo apt-get install php7.0 php7.0-cli php7.0-common
sudo apt-get install php7.0-curl php7.0-gd php7.0-mysql php7.0-bz2

return type: no scalar types like string, int, bool

function foo(): array {
    return [];
}
function 
swap(): void {}

Scalar Type Hints

<?php
declare(strict_types=1); // must be the first line

function isValidStatusCode(int $statusCode): bool {
    return isset(
$this->statuses[$statusCode]);
}

Nullable types

function test1(): ?string { return null; }
function 
test2(?string $name) { }

Null Coalesce Operator

$config $config ?? $this->config;
$config $config ?? $this->config ?? static::$defaultConfig;

array destructuring

$data = [
    [
1'Tom'],
    [
2'Fred'],
];
// list() style
list($id1$name1) = $data[0];
// [] style
[$id1$name1] = $data[0];
// list() style
foreach ($data as list($id$name)) {
    
// logic here with $id and $name
}
// [] style
foreach ($data as [$id$name]) {
    
// logic here with $id and $name
}
$data = [
    [
'id' => 1'name' => 'Tom'],
    [
'id' => 2'name' => 'Fred'],
];

// list() style
list('id' => $id1'name' => $name1) = $data[0];

// [] style
['id' => $id1'name' => $name1] = $data[0];

// list() style
foreach ($data as list('id' => $id'name' => $name)) {
    
// logic here with $id and $name
}

// [] style
foreach ($data as ['id' => $id'name' => $name]) {
    
// logic here with $id and $name
}
class Test {
    const 
PUBLIC_CONST_A 1;
    public const 
PUBLIC_CONST_B 2;
    protected const 
PROTECTED_CONST 3;
    private const 
PRIVATE_CONST 4;
}

multiple exception type

try {
} catch (
FirstException SecondException $e) {
}