Home>Article>Backend Development> Detailed explanation of the differences between PHP5.6 and PHP7

Detailed explanation of the differences between PHP5.6 and PHP7

coldplay.xixi
coldplay.xixi forward
2021-03-05 09:32:49 2735browse

Detailed explanation of the differences between PHP5.6 and PHP7

1. The difference between the two
1. The performance of PHP7.0 is twice that of PHP5.6.
2.PHP7.0 fully supports 64-bit.
3. Fatal errors that occurred before PHP7.0 have been changed to throwing agenda.
4. Added the null combination operator (??), 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 a constant array.

Recommended (free):PHP7
2. New features of PHP7.0
1. Type declaration
You can use strings (string), integers (int), floating point numbers (float), and Boolean values (bool) to declare function parameter types and function return values.
Scalar declaration type mode: mandatory 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
In PHP7.0, the previous fatal errors were avoided. Instead, errors were thrown by inheriting the Error class, allowing developers to have greater control over the program.
3. New operator "<=>"
Syntax: $x = $y <=> $z

If $y> $z, the value of $x is 1

If $y == $z, the value of $x is 0

If $y < $z, the value of $x is -1
4. New 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
Prevent Code injection of illegal data provides safer deserialization of data.
9. Namespace reference optimization
Files in the same folder support the introduction of array format
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. Open HugePage
4.PGO (Profile Guided Optimization)

The above is the detailed content of Detailed explanation of the differences between PHP5.6 and PHP7. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete