一个简单的yii2函数不起作用

时间:2017-07-31 08:16:07

标签: php yii2

我有两个功能,它们具有相同的目的,但我的写法不同。第一个工作正常,但第二个工作正常 - 但是我无法看到它们之间的区别。有人可以解释为什么第二个不能正常工作吗?

  1. public class SplashActivity extends Activity {
    
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(new SplashEnvironment(this, this));
        new Handler().postDelayed(new Runnable() {
    
        /*
         * Showing splash screen with a timer. This will be useful when you
         * want to show case your app logo / company
         */
    
        @Override
        public void run() {
            startActivity(new Intent(SplashActivity.this, MainActivity.class));
            finish();
            // close this activity
        }
    }, 3000);// time for spalsh screen
    }
    
  2. public function getClientPhone()
    {
    if (is_null($this->client_id)) {
        return '';
    }
    
    $phone = Client::getStaticClientPhone($this->client_id);
    
    if (is_null($phone)) {
        return '' ;
    }
    
    return $phone;
    }
    

1 个答案:

答案 0 :(得分:2)

更改

if ($this->client_id || $phone === null) {
    return '';
}

if ($this->client_id === null || $phone === null) {
    return '';
}

或者

if (!$this->client_id || $phone === null) {
     return '';
}