最近在看一个项目的源码,基础类的调用方法里面有这样一种语法,不是很理解,请教一下各位大神:
 $otherIc = &ic('other');      
false && $otherIc = new Other();
第二行是什么意思呢?
先清空 再重新new?
还是先判断是false 就new?
还是  先new 再判断?
还是压根不是 判断 就是直接new?

解决方案 »

  1.   


    $otherIc = '66';
    class Other{}
    //false 后面的不能执行
    false && $otherIc = new Other();
    //后面的执行了,$otherIc 变成了 Other 的实例
    //true && $otherIc = new Other();
    print_r($otherIc);
      

  2.   

    对于与或运算符 && ||
    当运算符为与,一旦前边的结果为假,就不再判断后边的结果,因为没有必要,结果必定为假;
    当运算符为或,一旦前边的结果为真,就不再判断后边的结果,结果必定为真。利用这个特点,可以用与或运算符当做if判断//$name为真才执行
    if($name) $person->name = $name;
    //可以写成
    $name && $person->name = $name;//$result为假才执行
    if(!$result) $obj->right = null;
    //可以写成
    $result || $obj->right = null;你的代码中,与符号前边直接是false,后边是不执行的。
      

  3.   

    别的我不说  就论这句 
    $otherIc = &ic('other');      
    false && $otherIc = new Other();
    我认为可以忽略  标红  这句话; 要说用意 也许作者就是想告诉你  &ic('other');函数返回值 就是    new Other();