Analysis of matters needing attention when passing by reference in PHP functions

不言
Release: 2023-03-29 18:12:02
Original
1487 people have browsed it

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));
Copy after login

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 ] )
Copy after login

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);
Copy after login

.

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

php function reference table

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!