PHP7 has been released for half a month and has recently had time to learn about the new features of PHP7, of course, the biggest feature of this version is the performance improvement. In the next is not a master, welcome to point out the mistakes, but also look forward to common communication
1. Added group support in the USE statement
Use foolibrary\bar\baz\{ClassA, ClassB, ClassC, CLASSD as Fizbo};
2. Increase?? Operator
Isset ($_get[' MyKey ')? $_get[' MyKey ']: "bulky
$_get[' MyKey ']?: "" When MyKey does not exist, it will report a E_notice
$_get[' MyKey '?? ' DefaultValue ' security will not be reported E_notice
$username = $_get[' user ']?? ' Nobody ';
3.64-bit PHP7 string length can exceed 2^31 bytes.
4. Increase Closure::call Support
Closure::call dynamically binds a closure function to a new object instance and invokes the function to execute it.
1<?PHP2 classValue {3 protected $value;4 5 Public function__construct ($value) {6 $this->value =$value;7 }8 9 Public functionGetValue () {Ten return $this-value; One } A } - - $three=NewValue (3); the $four=NewValue (4); - - $closure=function($delta) {Var_dump($this->getvalue () +$delta); }; - $closure->call ($three, 4); + $closure->call ($four, 4); -?> + //outputs Int (7), int (8)
5. Double quote strings and Heredocs support use \U{XXXXX} to declare Unicode characters.
6.define Support for logarithmic groups
1 Define Array (2 ' dog ',3 ' cat ',4 ' bird '5)); 6 Echo // outputs "Cat"
7. Add comparison operators <=>
$a <=> $b
0 if A is equal to B
1 if a is greater than B
1 if a is less than B
8.php global reserved words can be declared using
1 class View {2 Public function include $view ) {3 //... 4 }5 }
The Include keyword can be used as a normal string keyword
9. Scalar type (Int,float,string,bool) support
Increase the Declare (strict_types=1) Directive declaration whether the strict type check,
When the file header is declared declare (Strict_types=1)
1<PHP2 3 Declare(Strict_types=1);4 functionAddfloat $a,float $b):float {5 return $a+$b;6 }7Add (1, 2);//Float (3)
If the above code does not turn on declare (Strict_types=1) or declare (strict_types=0), PHP will automatically convert the parameters and return values to the specified type.
Open declare (Strict_types=1), throws an error if the parameter type is not FLAOT or if the return type is not float
10. Add the interface to provide a safe and convenient random number generator for the user layer. Rfc:https://wiki.php.net/rfc/easy_userland_csprng (Further discussion)
11. The yield from operator is added. Https://wiki.php.net/rfc/generator-delegation (Further discussion)
PHP7 new Features