PHP variable declaration and assignment, the variable name exists in the symbol table, and the value and class information exists in Zval, Zval contains four variables,is_ref,refcount,value,type,zval source code is as follows
Copy Code code as
With reference to PHP (the role of & symbol in front of a variable or function, object, etc.), let's look at the following procedure.
Copy Code code as follows:
$a = 100; Declaring variable A
$b = & $a; Declaring variable B,
What is the reference?Referencing in PHP means accessing the contents of the same variable with a different name. This is not like a C pointer, but instead, the reference is a symbolic table alias. Note that in PHP, variable names and variable
There is a difference between the pointers in the C language. The pointer in C language stores the reference of the variable's contents in memory in the address variable.
PHP references allow you to use two variables to point to the same content
Each php5.5 variable is stored in a variable container called Zval. A Zval variable container that contains two bytes of extra information in addition to the type and value of the variable: 1, the first is "Is_ref", and is a bool that
To understand this article, you should have some understanding of the implementation of variables in PHP5, the focus of this article is to explain the zval changes in PHP7.Due to a large number of detail descriptions, this article will be divided
Due to a large number of detail descriptions, this article will be divided into two parts: the first part mainly describes the implementation of Zval (Zend value) in PHP5 and PHP7 and the implementation of the reference. The second section will
PHP references (variables, functions, objects, etc. preceded by & symbols)The reference in PHP means: Different names access the same variable content.A reference to a variablePHP references allow you to use two variables to point to the same
PHP references (add & symbols before variables or functions, objects, etc.)The reference in PHP means: Different names access the same variable content.There is a difference between the pointers in the C language. In the C language, the pointer
Deeply parse the reference counting mechanism of PHP. After the PHP variable is declared and assigned a value, the variable name exists in the symbol table, and the value and class information exist in zval. zval contains four variables: is_ref,
We can see that the original value has been modified. it occurs after being referenced and assigned a value. However, before being assigned a value, the original variable will not change.
The code is as follows:
$ Foo = 'Bob'; // assign 'Bob'
We can see that the original value has been modified. It occurs after being referenced and assigned a value. However, before being assigned a value, the original variable will not change.
We can see that the original value has been modified. It
In php, you only need to add an & amp; before the original object to use the reference value assignment. for details about how to use the reference value, refer to the following explanations and examples.
ReferenceReferencing in PHP means accessing
When writing a PHP program, many people like to use a reference when passing parameters. Especially when an array is very large, it is more like adding.
The code is as follows:
Function binsearch (& $ arr, $ key, $ value){$ Low = 0;$ High = count
1.function Test ($arr) {}
echo Test (& $arr);
2.function Test (& $arr) {}
echo Test ($arr);
1 and 2 are the same effect.
3.function &test ($arr) {return $result;}
echo &test ($a); effective
echo test ($a); Returns a value, not a reference
Summary:
Interpretation of PHP-based references-Cancelling and locating references
Cancel reference
When unset is a reference, it only disconnects the binding between the variable name and the variable content. This does not mean that the variable content
A reference to PHP is to precede variables or functions, objects, etc. with & symbols. The reference in PHP means: Different names access the same variable content. There is a difference between pointers in C and C, where the contents of a variable
Using reference assignment in PHP only requires a & in front of the original object, $a = & $b; in fact, a reference in PHP is a variable of two different names pointing to the same value.
What is a reference?
Referencing in PHP means accessing the
The Reference type is used in many computer languages and exists as a very powerful and practical feature. it has implementations similar to pointers, but it is different from pointer
The Reference type is used in many computer languages and exists
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.