Some new features of PHP7

Source: Internet
Author: User
Tags zend

new feature Preview

1 2 3 4 5 6 7 8 9 10 11 Zend Engine upgrades to Zend Engine 3, which is called PHP NG add abstract syntax tree, makes compiling more scientific 64-bit int supports unified variable syntax soundtrack for TLS-meaningful consistency for extended development of foreach loops new <=>, * * 、?? , the \u{xxxx} operator adds a declaration of the return type adds a scalar type to the declaration that the core error can be captured by an exception. Increased contextual sensitivity of lexical analysis

some features of removal

1. Removed some old extensions and moved to PECL (for example, MySQL)
2. Removal of Sapis support
3.<? Tags such as language= "PHP" are removed
The 4.16-in string conversion was abolished
?

1 2 3 4 5 PHP5 "0x10" = "//PHP7" "0x10"!= "16"


5.http_raw_post_data removed (can be replaced with php://input)
6. Static functions no longer support the invocation of a non-static function via an incompatible $this.
$o = & New classname{}, this is no longer supported
7.php.ini file removed # as a comment, uniform;

Some changes in behavior

parameter not defined with same name in support function
A constructor with the same name as a type is not recommended (no removal is currently removed and subsequent removal is removed)
The keywords string, int, float, and so on cannot be used as class names
Func_get_args () Gets the value of the current variable
?

1 2 3 4 5 6 7 8 9 10 11-12 function test ($num) {$num + +; Var_dump (Func_get_args () [0]);   }; Test (1)//php5 int (1)//php7 int (2)

Here is a selection of some of the main, core, for our phper more important characteristics of the introduction

PHP NG

The new PHP engine optimizes a lot of places, and as such, it makes PHP7 nearly twice times higher than php5 performance.

Reconstruction of Zval structure

On the left is the PHP5 zval (24 bytes), and the right side is the PHP7 zval (16 bytes);

It can be seen that the PHP7 Zval is more complex than the php5, but can be reduced from 24 bytes down to 16 bytes, why.

Each member variable in the C language has to occupy a separate memory space, and the member variable in the union is a shared memory space (PHP7 is used to replace struct in a struct). Therefore, although the member variable looks a lot more, but the actual occupied memory space is a lot of common but declined.

Replace the previous Hashtale structure with the new Zend array

Our PHP program uses the most, most useful, the most convenient and most flexible is the array, and php5 its bottom is Hashtable implementation, PHP7 use of the new Zend array type, performance and access speed have been greatly improved.
Some of the most commonly used, inexpensive functions directly become engine-supported opcode
?

1 2 3 4 Call_user_function (_array) => zend_init_user_call is_int/string/array/* => Zend_type_check strlen => LEN defined => zend+defined

Uses new memory allocations, manages the way, reduces the memory waste
Optimization of core sequencing Zend_sort
?

1 2 3 4 5 PHP5-fast sort (unstable sort) Array (1 => 0, 0 => 0)//php7-Quick sort + Select sort (Stable sort) Array (0 => 0, 1 => 0)

Use selection for less than 16 elements, greater than 16 to split by 16 units, using the Select Sort, and then all together to use a quick sort. Compared to the previous, the internal elements from the unstable sort into a stable sort, reduce the number of elements exchanged, reduce the number of memory operations, performance improvement 40%
Abstract syntax Tree

If we now have such a demand, to the PHP source file on the line syntax detection, to achieve coding specifications. PHP5 before the words, no AST, directly from the parser generated opcodes. You need to use some external PHP parser to do this, and PHP7 added AST, we can do it ourselves to implement such an extension, using the extension provided functions can directly get the file corresponding to the AST structure, and this structure is what we can identify, So you can do some optimization and judgment on this basis.

64-bit int support

Support for storing strings larger than 2GB
Supports uploading files of size greater than 2GB
Ensure that the string "64 bits" is 64bit on all platforms
A unified syntax variable?

1 2 3 4 5 6 7 $ $foo [' bar '] [' Baz ']//php5 ($ $foo) [' Bar '] [' Baz ']//PHP7: Follow the principle from left to right ${$foo [' Bar '] [' Baz ']}

improvements to the Foreach Loop ?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30-31 PHP5 $a = Array (1, 2, 3); foreach ($a as $v) {Var_dump (current ($a));} int (2) int (2) int (2) $a = Array (1, 2, 3); $b =& $a; foreach ($a as $v) {Var_dump (current ($a));} int (2) int (3) bool (false) $a = Array (1, 2, 3); $b = $a; foreach ($a as $v) {var_dump ($a);} int (1) int (1) int (1)//PHP7: The internal pointer to no longer operates the data $a = Array (1, 2, 3); foreach ($a as $v) {var_dump ($a)} int (1) int (1) int (1) $a = Array (1, 2, 3); $b =& $a; foreach ($a as $v) {var_dump ($a) int (1) int (1) int (1) $a = Array (1, 2, 3); $b = $a; foreach ($a as $v) {V Ar_dump (current ($a))} int (1) int (1) int (1)

A few new operators?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16-17 <=>-Compare the size of two numbers "-1: The former is less than the latter, 0: The former equals the latter, 1: The former is greater than the latter" Echo 1 <=> 2; -1 Echo 1 <=> 1; 0 echo 1 <=> 0; 1//* *-"A's B-time" Echo 2 * * 3; 8//?? -Improvement of ternary operators//PHP5 $_get [' name ']? $_get [' name ']: '; Notice:undefined index: ...//php7 $_get [' name ']??   '-> '; \U{XXXX}-Parse echo "\u{4f60}" for Unicode characters; You echo "\u{65b0}"; New

Return a declaration of a type?

1 2 3 4 5 6 7 8 9 10 11 function getInt (): int {return

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.