Allow Specifying keys in list ()
Square bracket syntax for array destructuring assignment
The following support effect, or a good
List ($a, $b) = Array ($b, $a);
[$a, $b] = [$b, $a];
foreach ($points as ["X" => $x, "y" => $y]) {
Var_dump ($x, $y);
}
This can be very handy and powerful when traversing.
Feeling these two features makes the array easier to use
Nullable Types
This is a shorthand scalar or null, useful, but not very good.
Generalize support of negative string offsets
This feature is good enough to simplify some simple string processing
Support Class Constant Visibility
For the time being, it's just that the class constants are perfect.
Void return Type
This limit function returns a value that is useful
At the same time, hoping to miexd,number something.
Catching multiple Exception Types
It's not good to have more cacth, but it's probably not very unusual.
The rest is obvious, there's no better discussion, so let's talk about it.
String indexes can use negative numbers
$str = ' abcdef ';
Var_dump ($str [-2]); => string (1) "E"
$STR {3} = '. ';
Var_dump ($STR); => string (6) "Abc.ef"
Var_dump (Isset ($str {4})); => bool (TRUE)
Var_dump (Isset ($str {10})); => bool (FALSE)
Void return type
If a method is set to return a void type, it will not be able to return any value
function foo (): void
{
return 1; Error, cannot have return
}
function foo (): void
{
Return That's right
}
function foo (): void
{
Also correct
}
Note, however, that NULL cannot be returned:
function foo (): void
{
return null; That's not going to work!
}
Finally, if the subclass wants to overwrite a method that returns void for the parent class, the return type cannot be changed.
class constant Visibility setting
Class Token
{
Default is Public property
Const PUBLIC_CONST = 0;
You can add visibility settings
Private Const PRIVATE_CONST = 0;
protected Const PROTECTED_CONST = 0;
Public Const PUBLIC_CONST_TWO = 0;
All constants can only be set once visibility
I can write that.
Private Const FOO = 1, BAR = 2;
}
Multiple Exception simultaneous Catch
try {
Some code ...
catch (ExceptionType1 | ExceptionType2 $e) {
It's useful if you have different exceptions that you want to deal with in one way.
catch (\exception $e) {
// ...
}
Well, the new features of PHP 7.1 are these, do you have any expectations?