Recently, when I read the thinkPHP source code, I saw that some judgment methods are reversed, for example: {code ...} why is it & #039; & #039; $ name instead of $ name & #039; & #039 ;? What are the differences between the two types? Thank you! When I recently looked at the thinkPHP source code, I found that some judgment methods are reversed, for example:
If (''= $ name) {// get all variables $ data = $ input; $ filters = isset ($ filter )? $ Filter: C ('default _ filter'); if ($ filters) {if (is_string ($ filters) {$ filters = explode (',', $ filters);} foreach ($ filters as $ filter) {$ data = array_map_recursive ($ filter, $ data); // parameter filtering }}}
Why is it ''= $ name, not $ name = ''?
What are the differences between the two types?
Thank you!
Reply content:
When I recently looked at the thinkPHP source code, I found that some judgment methods are reversed, for example:
If (''= $ name) {// get all variables $ data = $ input; $ filters = isset ($ filter )? $ Filter: C ('default _ filter'); if ($ filters) {if (is_string ($ filters) {$ filters = explode (',', $ filters);} foreach ($ filters as $ filter) {$ data = array_map_recursive ($ filter, $ data); // parameter filtering }}}
Why is it ''= $ name, not $ name = ''?
What are the differences between the two types?
Thank you!
To prevent you from having to write only one equal sign.
This should be personal habits, without any impact.
If a value = is written for anti-write, an error is reported directly. if it is being written, a value is assigned and no error is reported. this is mainly used to prevent errors.
Exception writing, as described by Lou, prevents missing a "=" number. if it is missing, an error will be reported.
It is a good coding habit. if we compare $ name = 'a', this expression will assign a value to $ name, and 'A' = $ name will not
Take a look at the book c Traps and defects.