Fall into the trap in PHP-null, 0, false, empty strings today, when I used the company framework for development and found that the data is updated, those empty strings are not updated to the database, that is to say, classes & #20284; at 0, empty strings, and null are not updated to the database after they appear: they are found during careful debugging and fall into the pitfalls in PHP-null, 0, false, empty string
When data is updated during development using the company's framework today, the null strings are not updated in the database, that is, they are similar to 0 and null strings, null is not updated to the database after it appears:
After careful debugging, we found that the empty () function is used:
if(!empty($params['id'])) { $filters[] = array('id', '=', $params['id']); }
Then, naturally, the condition is no longer met and the database is updated. what about this pitfall? Instead of empty (), use isset ():
if(isset($params['config_id'])) { $filters[] = array('config_id', '=', $params['config_id']); }
Differences between the two functions:
Empty is used to check whether the variable is empty. isset is used to check whether the variable is set:
In your own words:
Empty is used to determine whether the content stored in this variable is 0, null, false, and an empty string.
Isset indicates whether the variable has been declared. it can be a string of 0, null, false, and null.
Empty has a large range and isset has a small range.
If the judgment is very accurate: '=' is recommended. in this case, php will check whether the types and values of the two variables are completely like.
Therefore, emtpy, isset, ===needs to be properly used in scenarios.