Okay, this one gets down to the nitty-gritty details of what makes Yii work.
It seems to be pretty common practice to store the user entity in a variable like so:
$user = Yii::app()->user;
And that makes sense. The question is, how often should this be done? Does it make more sense to get and store the user entity once in each function where it’s needed, like so:
public function foo() {
$user = Yii::app()->user;
/* Code here */
$this->bar();
}
private function bar() {
$user = Yii::app()->user;
/* Code here */
}
Or, should I keep and pass the $user variable, like so:
public function foo() {
$user = Yii::app()->user;
/* Code here */
$this->bar($user);
}
private function bar($user) {
/* Code here */
}
What are the advantages and disadvantages, as far as memory and speed go?