Home > Backend Development > PHP Tutorial > PHP variable reference Analysis of reference passing precautions for PHP function value transfer

PHP variable reference Analysis of reference passing precautions for PHP function value transfer

WBOY
Release: 2016-07-28 08:28:57
Original
1078 people have browsed it

The example in this article describes the precautions for passing by reference when passing values ​​in PHP functions. Share it with everyone for your reference, the details are as follows:

Strict standards: Only variables should be passed by reference

I found this sentence in the online information:

This problem will occur in php5.3 and above versions, and it should be the same It is 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 are higher versions so restricted?

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

& symbol specifies that the variable is passed in, which is passed by reference. Just change

to:

$file_name_arr = explode(".",$file_name);
$suffix = array_pop($file_name_arr);

Copy after login

.

Actually, it’s just 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.

Readers who are interested in more PHP-related content can check out the special topics of this site: "Introduction Tutorial on PHP Object-Oriented Programming", "Summary of PHP Mathematical Operation Skills", "Summary of PHP Office Document Skills (including word, excel, access) , ppt)", "Complete PHP Array (Array) Operation Skills", "PHP Data Structure and Algorithm Tutorial", "php Programming Algorithm Summary", "php Regular Expression Usage Summary", and "php Common Database Operation Skills Summary" 》

I hope this article will be helpful to everyone in PHP programming.

The above introduces the analysis of PHP variable reference and the reference passing precautions for PHP function value transfer, including the content of PHP variable reference. I hope it will be helpful to friends who are interested in PHP tutorials.

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