Home  >  Article  >  Backend Development  >  Understanding of php7 (with detailed tutorial)

Understanding of php7 (with detailed tutorial)

慕斯
慕斯Original
2021-06-01 11:38:492831browse

The last article introduced you to "Continue learning-AJAX PHP (with source code)". This article continues to introduce new content to you-PHP7. I believe you have already had a little experience with php7. understanding and aroused strong interest, let’s go and have a look now! ! !

Understanding of php7 (with detailed tutorial)

The PHP7 version has made adjustments to the variable parsing mechanism. The adjustments are as follows:

1. Indirect variables, attributes and method references are all Explain in order from left to right:

 $$foo['bar']['baz'] // interpreted as ($$foo)['bar']['baz']
 $foo->$bar['baz']   // interpreted as ($foo->$bar)['baz']
 $foo->$bar['baz']() // interpreted as ($foo->$bar)['baz']()
 Foo::$bar['baz']()  // interpreted as (Foo::$bar)['baz']()

If you want to change the order of explanation, you can use curly brackets:

${$foo['bar']['baz']}
$foo->{$bar['baz']}
$foo->{$bar['baz']}()
Foo::{$bar['baz']}()

2. The global keyword can now only refer to simple variables

global $$foo->bar;    // 这种写法不支持。
global ${$foo->bar};  // 需用大括号来达到效果。

3. It is useless to enclose variables or functions with parentheses

function getArray() { return [1, 2, 3]; }
$last = array_pop(getArray());
// Strict Standards: Only variables should be passed by reference
$last = array_pop((getArray()));
// Strict Standards: Only variables should be passed by reference

Note that the call in the second sentence is enclosed in parentheses, but this strict error is still reported. Previous versions of PHP would not report this error.

4. The order of array elements or object attributes automatically created during reference assignment is different from before.

$array = [];
$array["a"] =& $array["b"];
$array["b"] = 1;
var_dump($array);
PHP7产生的数组:["a" => 1, "b" => 1]
PHP5产生的数组:["b" => 1, "a" => 1]

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of Understanding of php7 (with detailed tutorial). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn