1. Scalar type declaration
The following type parameters can now be used: string (string), integer (int), floating point number ( float), and Boolean (bool). In the old version, function parameter declarations could only be (Array $arr), (CLassName $obj), etc. Basic types such as Int, String, etc. could not be declared.
2. Return value type declaration
PHP 7 adds support for return type declaration. The return type declaration specifies the type of function return value. The available types are the same as The same types are available in the parameter declaration.
3. Null merging operator
There are a lot of cases where ternary expressions and isset() are used simultaneously in the project, and the null merging operator (? ?) This syntactic sugar. If the variable exists and is not NULL, it returns its own value, otherwise it returns the second operand.
旧版:isset($_GET[‘id']) ? $_GET[id] : err; 新版:$_GET['id'] ?? 'err';
4. Combination comparison operator
The combination comparison operator is used to compare two expressions. It returns -1, 0 or 1 when $a is less than, equal to or greater than $b respectively.
5. Anonymous class
Now supports instantiating an anonymous class through new class.
Recommended tutorial: PHP video tutorial
The above is the detailed content of The syntax difference between php5 and php7. For more information, please follow other related articles on the PHP Chinese website!