[PHP] Onlyvariablesshouldbepassedbyreference

Source: Internet
Author: User
[PHP] Onlyvariablesshouldbepassedbyreference
A php Error was encountered Severity: Runtime Notice Message: Only variables shocould be passed by reference $ file_name = $ _ FILES [$ upload_name] ['name']; $ file_extension = end (explode ('. ', $ file_name); // error on this line cause: when getting the suffix, use the end function to point the internal pointer of the array to the last element, while the end function is used to reference the passed value. The problem is, that end requires a reference, because it modifies the internal representation of the array (I. e. it makes the current element pointer point to the last element ). the result of explode ('. ', $ file_name) cannot be turned into a reference. this is a restriction in the PHP language, that probably exists for simplicity reasons. the array. this array is passed by reference because it is mo Dified by the function. this means you must pass it a real variable and not a function returning an array because only actual variables may be passed by reference. solution: (1) define a variable to obtain the value after explode, and then use the end function: $ parts = explode ('. ', $ file_name); $ file_extension = end ($ parts); (2) use the substr and strrchr functions to retrieve the file suffix: $ ext = substr (strrchr ($ file_name ,'. '), 1); (3) use the pathinfo function to get the file suffix: $ file_ext = pathinfo ($ file_name, PATHINFO_EXTENSION); end () function points the internal pointer of the array to the last element, and returns the value of this element (if successful ). The pathinfo () function returns the file path information in an array. Reference link: http://www.w3school.com.cn/php/func_array_end.asp  http://www.w3school.com.cn/php/func_filesystem_pathinfo.asp  http://stackoverflow.com/questions/4636166/only-variables-should-be-passed-by-reference 

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.