PHP Error : Unparenthesized `a ? b : c ? d : e` is deprecated. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)`

PHP

I've updated my web application to PHP 7.4. Now I receive a couple of the following PHP errors due to my codes:

PHP Error : Unparenthesized `a ? b : c ? d : e` is deprecated. 
Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)`

I've multiple statements like this in my code and I don't know how to fix this problem. This is one code snippet I'm using. Could some one guide me to fix this PHP error?

$userIsLoggedIn = $userSession ? true : $oldUserSession ? true : false;
Programming Question created: 2020-10-10 03:52 feedMeNow

9

Since PHP 7.4 nested inline operations need brackets on each operation to ensure the whole operation is handled correct. 

To fix a simple nested operation like yours you just need to add brackets on the second operation like this: 

$userIsLoggedIn = $userSession ? true : ($oldUserSession ? true : false);

The following advanced example shows you how to fix this PHP error in a case of a tripple nested operation:

$result = $a ? true : ($b ? true : ($c ? true : false));
answered 2020-10-10 05:02 flick