2

Possible Duplicate:
Can't use method return value in write context

I sometimes encountered this error Can't use method return value in write context. However, I don't know what does WRITE CONTEXT means in this sentence. Could someone tell me a little general explaination of it.

Thank you.

The code for this error if you want to refer to is on line if(empty($this->loadUser())) However just to clarify, I just want to find out the meaning of "write context":

public function verify()
{
    if(empty($this->loadUser()))
        $this->addError('username','Incorrect username.');
    else
    {
        $user = $this->loadUser();
        $project = $this->loadProject($pid);

        $project->associateUserToProject($this->loadUser());
        $project->associateUserToRole($this->role, $this->user->id)

    }
}

public function loadUser() {
    return User::model()->findByAttributes(array('username'=>$this->username));
}
4

2 回答 2

1

empty () is not a function really. It is a construct or macros, if you please. It means you cannot pass an object to it as argument. Just pure variables.

$is_use = $this->loadUser();
if (empty ($is_use))
{
   ...
}
于 2012-08-07T16:02:21.420 回答
1

empty only takes variables as an arg. empty() only checks variables as anything else will result in a parse error.

http://php.net/manual/en/function.empty.php

于 2012-08-07T16:02:32.840 回答