The empty function that PHP is prone to use incorrectly
?
Written in the official PHP manual,
?
Checks if a variable is empty.
If Var is a non-null or nonzero value, empty () returns FALSE. In other words, "", 0, "0", NULL, FALSE, Array (), Var $var; and objects that do not have any properties will be considered empty and return TRUE if Var is empty.
?
It was then solemnly stated in its handbook,
?
Empty () detects only variables and detects anything that is non-variable will result in parsing errors. In other words, the statement behind will not work: Empty (Addslashes ($name)).
?
Empty is used to detect whether the variable is empty, which is often used in website programming, for example, we submitted the user's user name in the foreground page, when we need to determine whether it is empty, if it is empty, let him resubmit, then we need to use the function trim, that is, filter out the space on both sides, Then test with empty.
?
If (Empty (Trim ($_get[' username ')) {...}
?
However, when we ran this code, it was an error. The reason is that "empty () only detects variables ", and the exact value returned by trim is not a variable. So empty executes the error when it comes here. The method of modification is also very simple, the first method:
?
If (Trim ($_get[' username ' = = ') {...}
?
The second method, increase the intermediate variables:
?
$username = Trim ($_get[' username '), if (empty ($username)) {...}
?
The recommended approach is to use the validation framework in your project to solve this problem.