Changes in PHP7

Source: Internet
Author: User

PHP7 to the depth of Zend optimization, so that PHP7 speed greatly increased, nearly 5 times times faster than php5.0~5.6, but also reduce the use of PHP system resources

The following is a few changes PHP7 than the larger:

1, abstract syntax tree: The previous version, PHP code in the parsing phase directly generated ZENDVM, so that the compiler and the actuator coupled together, resulting in modification of either party will cause the other side of the modification, PHP7 added the abstract syntax tree, the first PHP code parsing generated an abstract syntax tree, Then the abstract syntax tree is compiled into the ZENDVM directive, the addition of the abstract syntax tree makes PHP compiler and executor very good isolation, the compiler does not bite the rules of the generation of instructions, and then the executor according to their own rules to compile the abstract syntax tree into corresponding instructions, The actuator also does not need to be concerned about the interpretation of the instruction's grammatical rules.

2, Native tls:php provides a thread-safe resource Manager, the global resources are thread-isolated, different threads do not interfere with each other, the use of global resources need to get the resource pool of this thread, this process is more time-consuming, the implementation of all functions need to speed up the receiving resource pool parameters, Manner is not elegant. PHP7 uses nvtive TLS (thread-local storage) to save the resource pool of threads, simply by __thread a global variable so that the global variable is a thread-exclusive, and the changes of different threads do not affect each other.

3. Specify function parameters, return value type:

function foo (string $name): array{return [];

}

The parameter of this function must be a string type, the return value must be an array type, otherwise the error is returned

4, Zval structure changes: is the internal structure of PHP, Zval has a more important member REFCOUNT_GC, it records the reference count of variables, reference counting is the basis for implementing variable automatic recovery in PHP, that is, the record variable how many places a mechanism to use, The php5.x reference count is in Zval instead of the specific value, causing the variable to replicate two structures, PHP7 the reference count to the specific value, which is more reasonable because zval is actually the variable name and value is the real value. In addition, the size of the zval is reduced from 24byte to 16byte, which is an optimization point where PHP7 can reduce system resource consumption.

5, exception handling: php5.x Many operations will directly throw error errors, PHP7 the majority of errors to throw the exception, so you can get through the Trycatch, new exception handling to make error handling more controllable.

6, Hashtable change: Hash table is also known as a hash table. It is an internal implementation mechanism of the powerful array () type in PHP, and is a structure used frequently in the kernel, the size of the hashtable structure is reduced from 72byte to 56byte, and the array element bucket mechanism is reduced from 72byte to 32byte

7, Actuator: In the PHP7 is no longer used in the way of parameters, but the Execute_data, opline through the register to store, to avoid the frequent access to the stack operation caused by the transfer, while the register compared to memory access faster, this optimization makes PHP performance of about 5% of the upgrade.

8. New parameter parsing method

-------excerpt from The Anatomy of the PHP kernel

Changes in PHP7

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.