When I looked at thinkPHP source code recently, I saw that some judgment methods are written in reverse, for example:
<code>if(''==$name) { // 获取全部变量 $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); // 参数过滤 } } }</code>
Xiaobai, please explain why it is ''==$name instead of $name ==''?
What is the difference between the two?
Thank you!
When I looked at thinkPHP source code recently, I saw that some judgment methods are written in reverse, for example:
<code>if(''==$name) { // 获取全部变量 $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); // 参数过滤 } } }</code>
Xiaobai, please explain why it is ''==$name instead of $name ==''?
What is the difference between the two?
Thank you!
In case you just wrote an equal sign and don’t know it yet.
This should be just a personal habit and has no impact at all
If you write it backwards, if you write an =, an error will be reported directly. If you write it forward, it will assign a value and no error will be reported. It is mainly to prevent errors
Abnormal writing method, as mentioned on the first floor, prevent missing a "=" sign, otherwise an error will be reported
A good coding habit. If the comparison is written as $name='a', this expression is to assign the value a to $name. If 'a'=$name, it will not
If you have time, you can read the book "C Traps and Defects".