Loka
Loka

Reputation: 53

PHP error, if-statement

Whats wring 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

Upvotes: 5

Views: 2204

Answers (4)

Adam Pointer
Adam Pointer

Reputation: 1492

just checking if($this->session->flashdata('login_error')) will return false if the result of this function is a boolean FALSE or NULL

Upvotes: 1

tvkanters
tvkanters

Reputation: 3523

isset only checks if a variable in instantiated. Since you can only return instantiated variables, isset is invalid there. Your best bet would be to do it like:

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

Upvotes: 1

jeroen
jeroen

Reputation: 91752

You can´t use a function with isset like that. What you could do is something like:

$txt = $this->session->flashdata('login_error');
if(!empty($txt))
{
     echo "You entered an incorrect email or password!";
}

Upvotes: 1

deceze
deceze

Reputation: 522412

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.

Upvotes: 12

Related Questions