The following if condition is causing an error:
if( !empty ($this -> session -> userdata( 'user_id') ) )
{
$user_id = $this -> session -> userdata( 'user_id' );
}
else
{
$error = "ID doesn't exist";
}
I get following error:
Fatal error: Can't use method return value in write context in (line number)
How can I fix it?
Replace the first
ifstatement withif( ! $this->session->userdata('user_id') ).The
emptyfunction check if a variable is empty butuserdatais a function. Additionally, for your information, according to the CodeIgniter documentation, theuserdatafunction returnsFALSEif the item doesn’t exist, which means that ifuser_iddoesn’t exist in your session, the code in theelsewill be executed.