Differences between PHP5.5 and empty functions in earlier versions _ PHP-php tutorial

Source: Internet
Author: User
Tags parse error
This article mainly introduces the differences between PHP5.5 and the empty function of earlier versions. during development, note that if your local PHP development version is PHP5.5 or later, and the server is lower than PHP5.5, pay more attention to this problem. If you need it, you can refer to it as one of my favorite functions. Today, I finally find the devil of this function. I wrote the following code to test everything locally, and then I went to the server to get SB.
The Code is as follows:
If (strlen ($ passwd) <6 | empty ($ preg_replace ("/\ d/", "", $ passwd ))){
// Do something
}
The password must be greater than six digits and cannot be composed of only digits. After searching server logs, the following error is found:
The Code is as follows:
PHP Fatal error: Can't use function return value in write context in/xxx/xx. php on line xxx

Google: probably, the empty parameter cannot be a function. I rely on it. It is good to be local. I can see that the local PHP is 5.5, and the server is 5.3. Does this function evolve between two versions? I searched for official PHP documents and found no clues. Then I searched google and accidentally clicked on the PHP English document interface. Below the introduction of the empty function, I found a line of small words:
The Code is as follows:
Note:
Prior to PHP 5.5, empty () only supports variables; anything else will result in a parse error. in other words, the following will not work: empty (trim ($ name )). instead, use trim ($ name) = false.

The devil, not Chinese users. To sum up the use cases of empty functions:

1. PHP versions earlier than 5.5, this function is used to check whether the value of the variable is 0, false, null String, null. Any parameter in non-variable form causes this function to report an error.
2. the PHP 5.5 function can be applied to any value, not limited to variables. Can be constants, function return values, and so on.

Related Article

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.