Talking about the important new characteristics of PHP7 and the php7_php course

Source: Internet
Author: User
Tags parse error scalar

A brief talk on the important new characteristics of PHP7 and PHP7


So far, PHP has officially released the RC5 version of PHP7, which is expected to release the first official version around November! For now, PHP7 's major features are definitely in shape and there will be no more changes. Some of the iterations that follow are mainly fixes, optimizations and the like. Here's what we've been waiting for. PHP7 will have those major changes ...

New feature Preview

Zend Engines upgrade to Zend Engine 3, the so-called PHP ng adds abstract syntax tree, makes compiling more scientific 64-bit int supports unified variable syntax for TLS-improved conformance foreach loops for extended development add <=>, * * 、?? The \u{xxxx} operator added a declaration of the return type to increase the declaration of a scalar type core error can be caught by exception by adding context-sensitive lexical analysis

Some of the features removed

1. Removed some old extensions, moved to pecl (e.g. MySQL)
2. Removal of Sapis support
3.<? and <? Language= "PHP" such as the label was removed
4.16 binary string conversion was abolished

PHP5 "0x10" = "+"//PHP7 "0x10"! = "16"


5.http_raw_post_data removed (can be replaced with php://input)
6. Static functions are no longer supported to invoke a non-static function through an incompatible $this.
$o = & New classname{}, no longer supports such a notation
7.php.ini file removed # as a comment, unified with; go to comment

Some changes in behavior

Not supported function definition parameter with same name
Constructors with the same name as the type are deprecated (not currently removed and subsequent removal)
These keywords, such as String, int, float, cannot be used as the class name
Func_get_args () Gets the value of the current variable

function test ($num) {  $num + +;  Var_dump (Func_get_args () [0]);}; Test (1)//php5int (1)//php7int (2)

Here's a selection of some of the main, core, features that are important to our phper.

PHP NG

The new PHP engine optimizes a lot of places, and officially because of this, it makes PHP7 nearly twice times faster than PHP5 performance!

Reconstruction of Zval structure

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

It can be seen that the zval of PHP7 is more complicated than php5, but it can be reduced from 24 bytes to 16 bytes.

In C, each member variable of a struct has to occupy a separate memory space, and the member variable in the union is a shared piece of memory space (a large number of unions are used in PHP7 to replace the struct). As a result, although member variables look a lot more, the actual amount of memory space that is occupied is much more common, but it's down.

Replace the previous Hashtale structure with the new Zend array

Our PHP program uses the most, the most useful, the most convenient, the most flexible is the array, and php5 its bottom is Hashtable implementation, PHP7 use the new Zend array type, performance and access speed has been greatly improved!
Some very common, less expensive functions become the engine-backed opcode directly.

Call_user_function (_array) = zend_init_user_callis_int/string/array/* = Zend_type_checkstrlen = ZEND_ strlendefined = zend+defined

Use of new memory allocation, management methods, reduce the waste of memory
Optimization of core Sort Zend_sort

PHP5-Quick sort (non-stable sort) Array (1 = 0, 0 = 0)//php7-Quick sort + Select sort (Stable sort) Array (0 = 0, 1 = 0)

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

If we have such a demand now, to PHP source files on the line syntax detection, implementation code specification. PHP5 before the words, no AST, directly from the parser generated opcodes! Need to use some external PHP syntax parser to implement, and PHP7 added AST, we can implement such an extension ourselves, using the extension provided by the function can directly get the file corresponding to the AST structure, and this structure is what we can recognize, So we can do some optimization and judgment on this basis.

64-bit INT support

Support for storing strings larger than 2GB
Supports uploading files larger than 2GB in size
Guaranteed string "64-bit" is 64bit on all platforms
Unified syntax Variables

$ $foo [' bar '] [' Baz ']//PHP5 ($ $foo) [' Bar '] [' Baz ']//PHP7: Follow the principle from left to right ${$foo [' Bar '] [' Baz ']}

Improvements to the Foreach Loop

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 (current ($a));} int (1) int (1) int (1)//PHP7: The internal pointer of the data is no longer manipulated by $ A = Array (1, 2, 3), foreach ($a as $v) {Var_dump (current ($a))}int (1) int (1) int (1) $  A = Array (1, 2, 3), $b =& $a; foreach ($a as $v) {Var_dump (current ($a)) int (1) int (1) int (1) $a = Array (1, 2, 3); $b = $a; foreach ($a as $v) {Var_dump (current ($a))}int (1) int (1) int (1)

A few new operators

<=>-compares 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;//-1echo 1 <=> 1;//0echo 1 <=> 0;//1//* *-"A's B-square" Echo 2 * * 3;//8//?? -Improvement of ternary operator//php5$_get[' name ']? $_get[' name ']: ';//notice:undefined index: ...//php7$_get[' name '?? //\U{XXXX}-parsing of Unicode characters echo "\u{4f60}";//You echo "\u{65b0}";//New

Declaration of the return type

function getInt (): int {  

Declaration of scalar types

function getInt (int $num): int {  return $num;}; GetInt ("test");//php5#php catchable fatal error:argument 1 passed to GetInt () must is an instance of int, string given...// Php7#fatal error:uncaught typeerror:argument 1 passed to GetInt () must is of the type Integer, string given ...

The core error can be caught by an exception

try {  non_exists_func ();} catch (Engineexception $e) {  echo "Exception: {$e->getmessage ();} \ n ";} Here with PHP7 try to still can't catch, but see bird brother introduced said is feasible ... #Exception: Call to undefined function non_exists_func ()

A sensitive lexical analysis of the upper and lower questions

Php5class Collection {public function foreach ($arr) {}} #Parse error:parse error, expecting ' "identifier (t_string)". .//php7class Collection {public  function foreach ($arr) {} public  function in ($arr) {} public  function where ($condition) {} public  function order ($condition) {}} $collection = new collection (); $collection->where ()->in () foreach ()->order ();

Almost, basically put their initial understanding of the PHP7, which there must be a lot of wrong, low-level mistakes, I hope that the brothers in time to correct, I am good change, make a note! Hey!

http://www.bkjia.com/PHPjc/1063901.html www.bkjia.com true http://www.bkjia.com/PHPjc/1063901.html techarticle a brief talk on the important new characteristics of PHP7, php7 so far, PHP has officially released the RC5 version of PHP7, it is expected to release the first official version around November! Now for PHP ...

  • Related Article

    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.