GabrielVa
GabrielVa

Reputation: 2388

Fatal error: Can't use function return value in write context in

Im getting a fatal error in my php code, I'm more of a SQL guy here so a little bit of guidance would be much appreciated.

if (isset(Auth::check() || Auth::attempt())) {  $auth_id = Auth::user()->id; }

Fatal error: Can't use function return value in write context in. I thought the code is right but perhaps I am writing it wrong?

Upvotes: 0

Views: 44

Answers (1)

Marc B
Marc B

Reputation: 360602

This is totally wrong:

(isset(Auth::check() || Auth::attempt()))

isset checks for the existence of a variable. You're not doing that. You're testing for the existence of the result of a logical OR operation.

By definition, a logical operation will ALWAYS produce a result, so there is exactly ZERO point in testing for the existence of that result. You most likely just want to test if that OR operation evalutes to true/false, in which case isset() is utterly useless anyways.

Try

if (Auth::check() || Auth::attempt()) { ... }

instead. Or whatever logic is appropriate for the return values you get from those two calls.

Upvotes: 2

Related Questions