As one of my favorite functions, today I have finally discovered the devil of this function. I wrote the following code freely. I tested everything locally and went to the service as B. If (strlen ($ passwd) 6 | empty ($ preg_replace (d, $ passwd) {dosomething} roughly means that the password must be greater than 6 digits cut
As one of my favorite functions, today I have finally discovered the devil of this function. I wrote the following code freely. I tested everything locally and went to the service as B. If (strlen ($ passwd) 6 | empty ($ preg_replace ("/\ d/", "", $ passwd ))) {// do something} indicates that the password must be greater than six digits.
As one of my favorite functions, today I have finally discovered the devil of this function. I wrote the following code freely. I tested everything locally and went to the service as B.
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:
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:
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:
- In versions earlier than PHP 5.5, this function is used to check whether the value of the variable is 0, false, empty string, or null. Any parameter in non-variable form causes this function to report an error.
- PHP 5.5 can be applied to any value, not limited to variables. Can be constants, function return values, and so on.
2 links are attached to see how the document is intended:
PHP: empty Chinese Reference
PHP: empty
Original article address: Be careful when using the empty function of PHP. Thank you for sharing it with the original author.