As we all know, php is a weak type of language, so we must be rigorous in the development process at ordinary times. do not easily bury some low-level pitfalls. The empty () function should be used with caution. let's take a look at the following examples:
As we all know, php is a weak type of language, so we must be rigorous in the development process at ordinary times. do not easily bury some low-level pitfalls. The empty () function should be used with caution. let's take a look at the following examples:
$ ZeroInt = 0;
Var_dump (empty ($ zeroInt); // bool (true)
$ ZeroIntStr = "0 ";
Var_dump (empty ($ zeroIntStr); // bool (true)
$ ZeroFloat = 0.0;
Var_dump (empty ($ zeroFloat); // bool (true)
$ ZeroFloatStr = "0.0 ";
Var_dump (empty ($ zeroFloatStr ));//Bool (false)Error-prone scenario: for example, if the latitude field is of the floating point type, php uses SQL to find out that conversion is a string type. if it is determined by empty, it is very likely to cause problems.
$ SpaceStr = ""; // Space
Var_dump (empty ($ spaceStr ));//Bool (false)Remember that the space is not empty
$ EmptyArr = array ();
Var_dump (empty ($ emptyArr); // bool (true)
$ EmptyStr = "";
Var_dump (empty ($ emptyStr); // bool (true)
$ Null = null;
Var_dump (empty ($ null); // bool (true)
$ EmptyArr2 = array (
Array ()
);
Var_dump (empty ($ emptyArr2 ));//Bool (false)This is also prone to errors.
Var_dump (empty ($ undefine); // bool (true)
?>
Php sacrifices rigor for convenience and flexibility. I think this is an embarrassing part of php. as a phper, you must start from yourself and strictly demand yourself, make programs written by yourself more stable.