1. Scalar type declaration
There are two modes: mandatory (default) and strict mode. You can now use the following type parameters, whether in forced or strict mode: string (String), Integer (int), floating-point number (float), and Boolean (bool).
2. return value type declaration
The return type declaration indicates the type of the function return value. The available types are the same as the types available in the parameter declaration.
<? PHP function arrayssum (array []):array{returnarray_map( function(array$array): int {returnarray_sum($array );} $arrays );} Print_r ([Arrayssum], [4,5,6], [7,8,9]); >
3, NULL merge operator
There is a large number of simultaneous use of ternary and isset () in the project, the addition of the null merge operator (??) This syntax (if the variable exists and the value is not NULL, it returns its own value, otherwise it returns the second operand.) )
4. Spaceship operator (combination comparator)
The spaceship operator is used to compare two expressions. When $ A is less than, equal to, or greater than $b, it returns-1, 0, or 1, respectively
<?PHP//integersEcho1 <=> 1;//0Echo1 <=> 2;//-1Echo2 <=> 1;//1//FloatsEcho1.5 <=> 1.5;//0Echo1.5 <=> 2.5;//-1Echo2.5 <=> 1.5;//1//StringsEcho"A" <=> "a";//0Echo"A" <=> "B";//-1Echo"B" <=> "a";//1?>
5. Define a constant array by define ()
<? PHP Define (' ANIMALS ', [' dog ', ' cat ', ' bird '); Echo // outputs "Cat"?>
6. Anonymous class
It is now supported to instantiate an anonymous class with the new class
<?PHPInterfaceLogger { Public function Log(string $msg);}classApplication {Private $logger; Public functionGetLogger ():Logger {return $this-logger;} Public functionSetlogger (Logger$logger) {$this->logger =$logger;}}$app=NewApplication;$app->setlogger (New class ImplementsLogger { Public function Log(string $msg) {Echo $msg;}});Var_dump($app-GetLogger ());?>
7. Unicode codepoint Translation Syntax
This accepts a Unicode codepoint in the form of 16, and prints a string in a double-quote or heredoc-enclosed UTF-8 encoded format. Any valid codepoint can be accepted, and 0 of the beginning can be omitted.
...... Cond
Summary of new functions and grammatical changes of PHP7