0

I am trying to return any array from function and its giving me following error

Can't use function return value in write context

This is the function :

public function chekusername($username){  
        $error[0] = false;
        $error[1] = 'please enter a username';
        if(empty(trim($username))) return $error;
        $where = array(array('username','=',$username));      
        $result=$this->model->selectwhere($this->model->gettablename(),$where);
        $error[1] = 'username already exist try different username';
        $success[0] = true;
        if(empty($result)) return $success; else return $error;
    }

I am getting error on this line

if(empty(trim($username))) return $error;
Bora
  • 10,529
  • 5
  • 43
  • 73
Abhishek Kumar
  • 2,136
  • 3
  • 24
  • 36

1 Answers1

0

Note: Prior to PHP 5.5, empty() only supports variables; anything else will result in a parse error. In other words, the following will not work: empty(trim($name)). Instead, use trim($name) == false.

You have to split like following:

$trimUsername = trim($username);

if(empty($trimUsername)) return $error;

Also you can use this format:

if(trim($username) == false) return $error;
Bora
  • 10,529
  • 5
  • 43
  • 73