What is the reason why thinkphp means judging and writing in reverse?

WBOY
Release: 2016-08-25 10:37:11
Original
817 people have browsed it

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>
Copy after login
Copy after login

Xiaobai, please explain why it is ''==$name instead of $name ==''?
What is the difference between the two?
Thank you!

Reply content:

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>
Copy after login
Copy after login

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".

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!