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 if
statement with if( ! $this->session->userdata('user_id') )
.
The empty
function check if a variable is empty but userdata
is a function. Additionally, for your information, according to the CodeIgniter documentation, the userdata
function returns FALSE
if the item doesn't exist, which means that if user_id
doesn't exist in your session, the code in the else
will be executed.
If you are using the sessions library of codeigniter then you don't need to check your data
codeigniter already does that for you.
if $this -> session -> userdata( 'user_id')
is empty or not set then it will be returned as false. So just a code something like that
$user_id = $this->session->userdata('user_id');
if(!$user_id){ }else{ $error = 'ID doesn't exist'; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With