In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Today, I will talk to you about what new features and improvements have been made in PHP7. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.
PHP 7 is a landmark version that not only adds many new features to make code more flexible, but also improves the underlying design and improves PHP execution efficiency.
What's New in PHP 7
The main new features in PHP 7 are as follows:
Scalar type declaration.
Function returns a value type declaration.
New null merge operator.
New combination comparator is added.
Supports the definition of constant arrays through define ().
Added support for anonymous classes.
Unicode codepoint translation syntax is supported.
Better closure support.
Provide filtering for unserialize ().
New IntlChar class is added.
Support use statements to import classes, functions, and constants from the same namespace.
Add the divisible function intdiv ().
Session_start () supports receiving array parameters.
Improvement and Optimization of PHP 7
Compared to previous versions, PHP 7 has some improvements at both the language syntax level and the underlying architecture level:
The main improvements at the syntax level are the addition of some new features, the removal of some extensions, the change of error exception handling and so on.
In the aspect of underlying structure, the Zval and Zend_String structures that store various variables are changed, the HashTable of Zend Array is optimized, and the function calling mechanism is improved.
In particular, the improvement of the underlying structure greatly improves the execution efficiency of PHP 7, making its execution speed about twice as high as that of PHP 5.
PHP 7 introduces strict mode switch
PHP is a weakly typed language, but supports the definition of variable types in PHP 7, introducing a switch instruction declare (strict_type=1);. Once this instruction is turned on, it forces the program under the current file to follow strict function parameter passing types and return types. If strict_type,PHP is not enabled, an attempt will be made to convert to the required type; when enabled, PHP will no longer do type conversion and an error will be thrown if the type does not match.
To use strict mode, an declare declaration directive must be placed at the top of the file. This means that it is strictly stated that scalars are file-based. This directive affects not only the type declaration of the parameter, but also the return value declaration of the function.
PHP 7 improves the error handling mechanism
In addition, in PHP 7, many fatal errors and recoverable fatal errors are converted to exceptions. These exceptions inherit from the Error class, which implements the Throwable interface (all exceptions implement this base interface).
This also means that when an error occurs, some error handling code in the previous code will not be triggered. Because in the PHP 7 version, the error handling mechanism that throws an exception is already used. If no Error exception is caught in the code, a fatal error is thrown.
PHP 7 optimizes Zval
In 2013, Hui Xinchen and Dmitry (one of the developers of the PHP kernel) made an attempt at JIT (Just In Time, just-in-time compilation, a software optimization technology) on the version of PHP 5.5.
The original execution flow of PHP 5.5 is to compile the PHP code into opcode bytecode through lexical and syntactic analysis, and then the Zend engine reads these opcode instructions and parses them one by one. They introduce type inference (TypeInf) after the opcode session, and then generate ByteCodes through JIT and then execute it.
With this technology optimization, the efficiency of PHP has not been significantly improved in the actual project, so they redesigned the underlying language structure of PHP. Zval is a carrier for storing variables in PHP and a struct implemented in C language. The Zval of PHP 5 occupies 24 bytes in memory, while the optimized Zval in PHP 7 occupies only 16 bytes, so the storage of variables becomes very simple and efficient.
PHP 7 optimizes the array
PHP 7 optimizes the HashTable implementation of arrays. The array storage form of PHP 5 is a HashTable that supports bi-directional linked lists. It not only supports hash mapping access elements through array key, but also traverses array elements by accessing bi-directional linked lists through foreach.
When we access the content of an element through the key value, it sometimes takes three pointer jumps to find the right content. The most important point is that the storage of these array elements is scattered in different memory areas, and when CPU reads, because they are probably not in the same level cache, CPU has to look in the subordinate cache or even memory areas, thus causing the CPU cache hit to drop, which in turn increases the time consuming.
The most important feature of the optimized Zend Array is that the whole array elements and the hash mapping table are all connected together and allocated in the same block of memory. If you are traversing an array of simple types of integers, it will be very efficient, because the array elements (Bucket) themselves are continuously allocated in the same block of memory, and the Zval of the array elements will store the integer elements internally, there is no longer a pointer chain, and all the data is stored in the current memory area.
Of course, the most important thing is that it can avoid a decline in the CPU cache hit rate.
PHP 7 improves function calls
PHP 7 also improves the function calling mechanism, reduces some instructions by optimizing the parameter transmission, and improves the execution efficiency.
After reading the above, do you have any further understanding of the new features and improvements of PHP7? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.