Home > Article > Backend Development > What is the difference between php5.6 and php7
The difference between php5.6 and php7: 1. A new function return type declaration is added in php7; 2. A scalar type declaration is added in php7; 3. Anonymous classes are added in php7; 4. PHP7 has removed some SAPI and extensions that are no longer supported.
The operating environment of this tutorial: windows10 system, PHP7.1 version, DELL G3 computer
1. The difference between the two
1.PHP7.0 has twice the performance than PHP5.6.
2.PHP7.0 fully supports 64-bit.
3.Fatal errors that occurred before PHP7.0 were changed to throwing agenda.
4. The null combination operator (??) is added, which is equivalent to the ternary operator.
5.PHP7.0 adds a new function return type declaration.
6.PHP7.0 adds a new scalar type declaration.
7. The formal parameter type declaration of a function in PHP7 can be a scalar. In PHP5, it can only be a class name, interface, array or callable (PHP5.4, that is, it can be a function, including anonymous functions). Now you can also use string, int, float and bool.
8. Anonymous classes are newly added in PHP7.0.
9.After PHP7.0, some old SAPI (server-side application programming port) and extensions that are no longer supported have been removed.
10.define can define constant arrays.
2. New features of PHP7.0
1. Type declaration
You can use string (string), integer (int), float Points (float), and Boolean values (bool) are used to declare the parameter types and function return values of the function.
Scalar declaration type mode: forced mode (default mode) and strict mode
declare(strict_types=1), must be placed at the top to ensure that the file execution is valid.
2. Exception handling
PHP7.0 avoids the previous fatal errors. Instead, it inherits the Error class and throws errors, allowing developers to have greater control over the program.
3. New operator "96b4fef55684b9312718d5de63fb7121"
Syntax: $x = $y 96b4fef55684b9312718d5de63fb7121 $z
If $y> $ The value of z, $x is 1
If $y == $z, the value of $x is 0
If $y < $z, the value of $x is -1
4. Add operation fee "??"
If the variable exists and the value is not NULL, return its own value, otherwise return the second operand.
5.define() defines constant array
6.Anonymous function
7.Unicode character format support (echo "/u{1234}")
8.Unserialize provides filtering features
Prevents code injection of illegal data and provides safer deserialized data.
9. Namespace reference optimization
The files in the same folder support the introduction of array form
3. How to give full play to the performance of PHP7
1. Turn on Opcache
zend_extension=opcache.so opcache.enable=1 opcache.enable_cli=1
2. Compile using GCC 4.8 or above
3. Turn on HugePage
4.PGO (Profile Guided Optimization)
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What is the difference between php5.6 and php7. For more information, please follow other related articles on the PHP Chinese website!