Home > Backend Development > PHP Problem > The syntax difference between php5 and php7

The syntax difference between php5 and php7

王林
Release: 2023-02-27 08:04:01
Original
5744 people have browsed it

The syntax difference between php5 and php7

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';
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template