As one of my favorite functions, today I have finally discovered the devil of this function. I wrote the following code to test everything locally, and then I went to the server to get SB.
Copy codeThe 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:
Copy codeThe 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:
Copy codeThe 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.