Strict Standards: Only variables shocould be passed by referen

Source: Internet
Author: User

This article introduces the Strict Standards: Only variables shocould be passed by reference in solution. For more information, see.

Php uses the built-in reset function to obtain the value of the first element of array. For example:

The Code is as follows: Copy code

$ Arr = array ('one', 'two', 'three ');

Echo reset ($ arr );

// The output result is one. If "Strict Standards" is enabled for php, the prompt "Strict Standards: Only variables shocould be passed by reference in" is displayed.

The Code is as follows: Copy code

$ Str = 'netingcn. com ';

Echo reset (explode ('.', $ str ));

Why? Let's first look at the definition of the reset function:

Function reset (array & $ array) {} can be seen from the definition that the reset accepts the parameter as an array reference. In the above Code, the return value of explode is not referenced by any array, so the above prompt is displayed under "Strict Standards. The solution is simple. You only need to write the reset (explode ('.', $ str) in two steps. The first step is to assign the return value of explode to a variable, and the second step is to use this variable as the reset parameter.

The above prompt is not just a reset function, as long as the parameter accepts the object reference, and the function return value is directly used to pass the value. For example, the built-in array_pop, shuffle, curent, next, prev, And next

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.