phpcodeigniterif-statement

Wraing a CodeIgniter's flashdata() method call in isset() emits: "Fatal error: Can't use method return value in write context"


What's wrong with this code?

if (isset($this->session->flashdata('login_error'))) {      // Line 39
    echo "You entered an incorrect email or password!";
}

I use CodeIgniter and session is loaded in autoload.php.

The error message I get is:

Fatal error: Can't use method return value in write context in /Applications/XAMPP/xamppfiles/htdocs/application/views/login_view.php on line 39


Solution

  • isset is only necessary if you're trying to work with variables that may not exist. In your case you're calling a function, which certainly exists. Hence you don't need and in fact can't use isset here. Just use if ($this->session->flashdata('login_error')) if you want to test whether the value is truthy.