[PHP] New Features of porting from PHP 5.6.x to PHP 7.0.x, 5.6.x7.0.x
New features:
1. scalar type declaration
String (string), INTEGER (int), floating point number (float), Boolean (bool), callable, array, self, Class/interface name
2. Return Value Type Declaration
Define parameter type and Return Value Type
Function test (int $ a): int {}
If the parameter is not passed as required, an exception is returned.
3. null merge Operator
Null merge operator (??) , Equivalent to a ternary Operator
$ Name = $ _ GET ['name']? "Test"; echo $ name;
4. spacecraft operators (composite comparison operators)
If $ a is less than, equal to, or greater than $ B, it returns-1, 0, or 1.
$ A <=> $ B
5. define a constant array through define ()
Define ('animal', ['Dog', 'cat', 'bird']);
6. Anonymous class
A function parameter must be of the forced type, which is completed using an anonymous class.
Interface Logger {
Public function log (string $ msg );
}
Function test (Logger $ logger ){
Echo $ logger-> log ('aaa ');
}
Test (new Class implements Logger {
Public function log (string $ msg ){
Return $ msg;
}
});
7. Unicode codepoint translation syntax
The complete Unicode character is called codepoint. Unicode sets a unified and unique binary encoding for each character in each language.
8. Provides Filtering for unserialize (), provides a safer way to unpackage unreliable data, and prevents potential code injection through whitelist.
9. Expected, assert-check whether an asserted is FALSE
10. Group use declarations
Classes, functions, and constants imported from the same namespace can now be imported at one time using a single use statement.
11. The generator can return expressions.
12. Generator delegation
13. Integer Division function intdiv ()
14. session options
Session_start () can accept an array as the parameter to overwrite the settings in the php. ini file.
15. CSPRNG Functions
Random_bytes () and random_int () are used to generate high-security random strings and random integers.
16. You can use the list () function to expand the objects that implement the ArrayAccess interface.
17. Other features