New features of PHP7 this article is based on new files at PHP release. link: PHP 7 new
Features
- Added ?? Operator
- Added <=> operato
New operators
Php // PHP 7 before writing: compare two numbers of function order_func ($ a, $ B) {return ($ a <$ B )? -1: ($ a> $ B )? 1: 0);} // The new PHP operator <=>, perfectfunction order_func ($ a, $ B) {return $ a <=> $ B ;}
- Added \ u {xxxxx} Unicode Codepoint Escape Syntax
You can use this method to output unicode characters directly.
Phpecho "\ u {1F602}"; // outputs (this is the question mark in square brackets. as it is a unicode character, it is not supported by the sg blog and released)
Added error_clear_last () function
A new function has not been thoroughly studied.
-
Implemented the RFC Scalar Type Decalarations v0.5. (Anthony)
Variable type declaration (int, float, string, bool)
Related syntax: declare (strict_types = 1 );
When strict_types is set to 0, PHP strictly determines the type of function parameters and return values.
What is important?
1 declare (strict_types = 1); it must be placed in the first line of the PHP file. this line cannot contain other content.
2 declare (strict_types = 1); only files inside the file will be affected. files containing the declared file will not be affected.
3. to determine whether a function or method is strongly typed or weak, check the file that declares the function or method. at the beginning
Whether there is declare (strict_types = 1);. if there is such a statement, it is strongly typed.
Syntax demonstration
Php // declare the writing method of the function return value type and function foobar (float $ abc) of the parameter type: int {return ceil ($ abc + 1 );}
The type of the method parameter is declared here. if it is not the corresponding type during the call, type conversion will be attempted first, and the converted value will be passed in.
- Mplemented the RFC Group Use Declarations. (Marcio)
There is nothing to say about this. PHP use introduces classes more conveniently and neatly.
Php // use FooLibrary \ Bar \ Baz \ {ClassA, ClassB, ClassC, ClassD as Fizbo} in the new syntax; // use FooLibrary \ Bar \ Baz \ ClassA in the previous syntax; 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)
Add some boundaries of the foreach syntax,
Https://wiki.php.net/rfc/php7_foreach
Implemented the RFC Generator Delegation. (Bob)
Enhanced the functions of Generator, which can implement many advanced features
Php
Implemented the RFC Anonymous Class Support. (Joe, Nikita, Dmitry)
Anonymous class. this is not detailed.
Implemented the RFC Context Sensitive Lexer. (Marcio Almada)
This feature is mainly because PHP's object-oriented feature is more user-friendly.
Some keywords such as foreach, list, and for can be used in class attributes or methods.
TODO
Sorry, I have a fever today. I can't write it down. I will try again later.