Source: www.wei-bolg.com? What is the difference between p152PHP and reference and address transfer? Pass: It is to assign the real parameter to the row parameter, which is equivalent to copying the same space. So the modification to the row parameter will not affect the real parameter? Phpfunctionaa ($ I) {$ I;} by mode $ m2; aa ($ m); echo $ m; Output $ m2? Transfer address: Yes
Source: http://www.wei-bolg.com /? P = 152 what is the difference between transferring a reference parameter and transferring an address in PHP? Pass: It assigns a real parameter to a row parameter, which is equivalent to copying the same space and modifying the row parameter, does not affect real parameters? Php functionaa ($ I) {$ I;} // by mode $ m = 2; aa ($ m); echo \ $ m = $ m; // output $ m = 2? Transfer address: Yes
Source: http://www.wei-bolg.com /? P = 152
Differences between passing a value in PHP and passing a reference and passing an address:
Pass value:
Is to assign the value of the real parameter to the row parameter, which is equivalent to copying the same space
The modification of the row parameter does not affect the value of the real parameter.
Function aa ($ I ){
$ I ++;
}
// By Value
$ M = 2;
Aa ($ m );
Echo "\ $ m = $ m"; // output "$ m = 2"
?>
Transfer address:
It is a special method for transferring values, but it only transmits an address, not a common such as int
After the address is passed, both the real parameter and the row parameter point to the same object.
Reference:
Actually passing parameters in address mode
After passing, the row parameters and real parameters are the same object, but their names are different.
Modifying the row parameter will affect the value of the real parameter.
That is, you only need to add the "&" sign before the parameter when calling the function. The memory address of the external value of the function is passed to the internal parameter. All operations within the function change the value of the External Parameter of the function.
Function aa (& $ I ){
$ I ++;
}
// Address-based
$ M = 2;
Aa (& $ m );
Echo "\ $ m = $ m"; // output "$ m = 3"
?>
Bytes -----------------------------------------------------------------------------------
The following is a better understanding of function calls.
Pass value:
The parameter stack is a copy of the parameter.
Any modification works on the copy and does not work on the original variable.
Pass pointer:
The stack is a copy of the pointer variable.
When you perform pointer decoding, the value of the Pointer Points to the original variable. Therefore, you can perform operations on the original variable.
Reference:
The stack is a referenced copy. Because the reference is directed to a variable, the reference operation is actually the operation of the variable to which it points. (The function is the same as passing a pointer, but referencing a grass paper with little knowledge of the pointer)
Bytes -----------------------------------------------------------------------------------
Basic Theory of function parameter transfer mechanism
In essence, the function parameter transfer mechanism is a problem where the call function (process) and the called function (process) communicate when the call occurs. There are two basic parameter transfer mechanisms: value transfer and reference transfer. The following describes the functions that call other functions as the main functions. The called functions are called functions.
In the passl-by-value process, the formal parameters of the called function are processed as local variables of the called function, that is, the memory space is opened in the stack to store the values of the real parameters put in by the main function, thus becoming a copy of the real parameters. The feature of value transfer is that any operation of the form parameter of the called function is performed as a local variable, without affecting the value of the real parameter variable of the main function.
During the pass-by-reference process, the form parameter of the called function opens up the memory space in the stack as a local variable, however, the address of the Real Variable put in by the main function is stored. Any operation of the called function on the form parameter is processed as indirect addressing. That is, the address stored in the stack is used to access the real variable in the main function. Because of this, any operation performed by the called function on the form parameter affects
Real variable.
Bytes -----------------------------------------------------------------------------------
We will only discuss the value transfer and reference:
The so-called value transfer means that only passing the object value to the target object is equivalent to copy; the system will re-open a completely identical memory space for the target object.
The so-called reference means passing the address of the object in the memory to the target object is equivalent to making the target object and the original object correspond to the same memory bucket. At this time, if you modify the target object, the data in the memory will also change.