This article is based on the new files when PHP was released, link address: PHP 7 new
Features at a glance
- Added?? operator
- Added <=> Operato
New operator
php//PHP 7: Compare the size of two numbers function Order_func ($a, $b) { return ($a < $b)? 1: (($a > $b)? 1:0);} PHP new operator <=>,perfectfunction Order_func ($a, $b) { return $a <=> $b;}
- Added \u{xxxxx} Unicode codepoint Escape Syntax
You can output Unicode characters directly using this method
Phpecho "\u{1f602}"; Outputs (this is the question mark inside the square brackets, because it is a Unicode character, the SG blog is not supported, published)
Added Error_clear_last () function
A new function, the specific function did not delve into
Implemented the RFC Scalar Type decalarations v0.5. (Anthony)
Variable type declaration (int, float, string, bool)
A grammar associated with it: Declare (Strict_types=1);
When Strict_types is set to 0,php, the function parameters and return values are strictly type judged
Need the main is
1 declare (Strict_types=1); Must be placed in the first line of the PHP file, this line cannot contain other content
2 declare (Strict_types=1); Only affects internal files, files that contain this claim file do not affect
3 Judging whether a function or method is strongly typed or weakly typed, look at the file that declares the function or method, at the beginning
Whether there is a declare (Strict_types=1), there is this sentence, is the strong type
Grammar Demo
php//declares that the function returns the type of the value and the parameter type function foobar (float $ABC): int { return ceil ($ABC + 1);}
The type of the method parameter is declared here, and when called, if it is not the corresponding type, the type conversion is attempted first and then the converted value is passed in
- mplemented the RFC Group use Declarations. (Marcio)
This is nothing to say, PHP use introduced class more convenient neat
php//new grammar notation use foolibrary\bar\baz\{ClassA, ClassB, ClassC, CLASSD as Fizbo};//previous syntax notation use Foolibrary\bar\baz\classa;use Foolibrary\bar\baz\classb;use Foolibrary\bar\baz\classc;use FOOLIBRARY\BAR\BAZ\CLASSD as Fizbo;
Implemented the RFC Continue Output buffering. (Mike)
Todo
Implemented the RFC Constructor behaviour of internal classes. (Dan, Dmitry)
Todo
Implemented the RFC Fix "foreach" behavior. (Dmitry)
Some boundaries of the foreach syntax are added for processing,
Https://wiki.php.net/rfc/php7_foreach
Implemented the RFC Generator delegation. (BOB)
Enhanced the functionality of the generator, which allows for many advanced features
php!--? php//usage, lightweight thread function g () {yield 1; Yield from [2, 3, 4]; Yield 5;} $g = g (); foreach ($g as $yielded) {var_dump ($yielded);} /*int (1) int (2) int (3) int (4) int (5) */
-
Implemented the RFC Anonymous Class support. (Joe, Nikita, Dmitry)
Anonymous class, this is not specifically described in
-
Implemented the RFC Context sensitive Lexer. (Marcio Almada)
This feature is primarily a more user-friendly object-oriented nature of PHP
in class properties or methods can use some keywords such as foreach,list,for
TODO
Sorry, a bit of a fever today, can't write down, will be free to continue