Friday, December 2, 2016

PHP 7.1 Released - Nullable types, Void Return Type, Class Constant Visibility and more

The PHP development team announced yesterday the release of PHP 7.1.0. This release is the first point release in the 7.x series.



The list of changes contains:
"-Nullable types

function answer(): ?int  {
    return null; //ok
}
 
function answer(): ?int  {
    return 42; // ok
}
 
function answer(): ?int {
    return new stdclass(); // error
}
- Void return type
function lacks_return(): void {
    // valid
}
function should_return_nothing(): void {
    return 1; // Fatal error: A void function must not return a value
}
- Class constant visibility modifiers
<?php
 
class Token {
 // Constants default to public
 const PUBLIC_CONST = 0;
 
        // Constants then also can have a defined visibility
        private const PRIVATE_CONST = 0;
        protected const PROTECTED_CONST = 0;
        public const PUBLIC_CONST_TWO = 0;
 
        //Constants can only have one visibility declaration list
        private const FOO = 1, BAR = 2;
}
- Iterable pseudo-type
- Square bracket syntax for list() and the ability to specify keys in list() 
- Catching multiple exceptions types
- And many more features and changes…"
Quoted from: http://php.net/releases/7_1_0.php

No comments:

Post a Comment