Summary of php5.6. x to php7.0. x characteristics
- 2021-12-21 04:15:33
- OfStack
This paper summarizes and analyzes the characteristics of php5.6. x to php7.0. x. Share it for your reference, as follows:
php5.6. x to php7.0. x features
1. Scalar type declaration
String (string), Integer (int), Floating Point (float), Boolean (bool), callable, array, self, Class/interface name
2. Return value type declaration
Define parameter types and return value types
function test(int $a):int{}
If you don't pass the conference as required, you will return an exception
3. null merge operator
null merge operator (? ? ), which is equivalent to the 3-yuan operator
name=name=_GET['name'] ?? "test";echo $name;
4. Spacecraft Operator (Combination Comparator)
It returns-1, 0, or 1 when a is less than, equal to, or greater than a is less than, equal to, or greater than b, respectively.
a<=>a<=>b
5. Defining an array of constants through define ()
define('ANIMALS', ['dog','cat','bird']);
6. Anonymous classes
A function parameter is forced to be typed, which is completed by using anonymous classes
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 Translational Grammar
The complete Unicode character is called codepoint, and Unicode sets a unified and only 1 binary code for each character in each language
8. Provide filtering for unserialize (), provide a more secure way to unpack unreliable data, and prevent potential code injection by whitelist
9. Expectation, assert-Checks if an assertion is FALSE
10.Group use declarations
Classes, functions, and constants imported from the same 1 namespace can now be imported once through a single use statement
11. The generator can return an expression
12.Generator delegation
13. Integer division function intdiv ()
14. Session Options
session_start () can accept 1 array as a parameter to override 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 objects that implement the ArrayAccess interface
17. Other characteristics
For more readers interested in PHP related contents, please check the topics on this site: "Summary of Common Functions and Skills of php", "Summary of Usage of php String (string)", "Encyclopedia of Operation Skills of PHP Array (Array)", "Introduction to Basic Grammar of PHP", "Introduction to Database Operation of php+mysql" and "Summary of Operation Skills of Common Database of php"
I hope this article is helpful to everyone's PHP programming.