The difference between PHP5.5 and previous versions of the empty function_PHP Tutorial

WBOY
Release: 2016-07-13 10:28:15
Original
869 people have browsed it

As one of my favorite functions, I finally discovered the devil of this function today. Yangsao wrote the following code, and everything was ok when tested locally, but it was SB on the server.

Copy code The code is as follows:

if(strlen($passwd) < 6 || empty($preg_replace(" /d/", "", $passwd))) {
//do something
}

The general meaning is that the password must be greater than 6 characters and cannot only consist of numbers. Searched the server log and found the following error:
Copy the code The code is as follows:

PHP Fatal error: Can't use function return value in write context in /xxx/xxx/xx.php on line xxx

After searching on Google, it probably means that the parameter of empty cannot be a function. Damn, the local area is obviously good. I checked that the local PHP is 5.5 and the server is 5.3. Has this function evolved between the two versions? I searched all the official PHP documents but didn't find any clues. Then I searched frantically on Google and accidentally clicked on the PHP English document interface. Under the introduction of the empty function, I found a line of small characters:

Copy the code 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.

Devil, you don’t want to trick Chinese users like this. Summarize the usage scenarios of empty function:

1. In versions before PHP 5.5, this function is used to check whether the variable assignment is 0, false, empty string, or null. Any non-variable parameter will cause this function to report an error.
2.PHP 5.5 This function can be applied to any value, not limited to variables. It can be a constant, a function return value, etc.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/802221.htmlTechArticleAs one of my favorite functions, I finally discovered the devil of this function today. I wrote the following code in Yangshasa, and everything was ok when tested locally, but it was SB on the server. Copy...
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