Home>Article>Backend Development> Understanding of php7 (with detailed tutorial)
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! ! !
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!