sar*_*nkg 3 yii yii-components
在Yii中$ model = new Users和$ model = new Users()之间有什么区别?
Basically there is no difference between the two statements. you can use any statement to create an object. The difference plays its role when you want to pass the arguments to initialize the constructor. eg:- Lets consider the case of declaring the scenario. for that you will use
$model= new User('login');
Run Code Online (Sandbox Code Playgroud)
This statement will bind the $model object with a scenario call 'login' which you can then use for validation purposes.
As you can see since you are not using () in case of $model = new Users; SO you cant create a scenario in this statement.
BUT this does not mean that you can never create a scenario now.
To create a scenario using $model = new Users; you need to write one more line i.e
$model->scenario='login';
Run Code Online (Sandbox Code Playgroud)
So from all above $model= new User('login'); is equal to
$model = new Users;
$model->scenario='login';
Run Code Online (Sandbox Code Playgroud)
Conclusion:- There is no difference.Both are same till the time you do not want to pass the argument.