This article mainly introduces the reference transfer precautions for PHP function value transfer, involving the setting of PHP configuration files and the use skills of array functions. Friends in need can refer to the following
The examples in this article describe PHP functions Notes on passing by reference. Share it with everyone for your reference, the details are as follows:
Strict standards: Only variables should be passed by reference
There is such a sentence in the information found online:
This problem will occur in php5.3 and above versions. It should also be related to the configuration of php. As long as you split this sentence into two sentences, there will be no problem. Because the parameters of array_walk are passed by reference, only specific variables can be passed by default in version 5.3 and above, and values cannot be returned through functions. Of course you can also modify error_reporting = E_ALL | E_STRICT in php.ini, but this does not comply with the specification after all.
$suffix = array_pop(explode(".",$file_name));
Why do higher versions have such restrictions?
I looked at the function prototype in the manual:
mixed array_pop ( array &$array ) bool array_walk ( array &$array , callable $funcname [, mixed $userdata = NULL ] )
The & symbol specifies the variables to be passed in, which is passed by reference.
can be changed to:
$file_name_arr = explode(".",$file_name); $suffix = array_pop($file_name_arr);
.
In fact, it only reports a warning. Not a fatal error. Normal results can be obtained. For example, it is normal to get the suffix of the file name here.
Related recommendations:
php function mkdir implements the method of recursively creating hierarchical directories
The above is the detailed content of Analysis of matters needing attention when passing by reference in PHP functions. For more information, please follow other related articles on the PHP Chinese website!