When coding with isset
i am getting an fatal error.I have searched stackoverflow but results are not satisfactory.
I am getting
Fatal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead)
My codes are
if (!isset( $size || $color )) {
$style = '';
}else{
$style = 'font-size : ' . $size . ';color:' . $color;
}
you shuold use this way
As mentioned in the comments (and the error message), you cannot pass the result of an expression to
isset
.You can use multiple isset calls, or reverse the logic of your if/else block and pass multiple parameters to isset, which i think is the cleanest solution:
You can clean this up a little further by setting the default value first, thus avoiding the need for an else section:
You could even use a ternary, though some people find them harder to read:
Your expression always return either true or false => In theory isset always return true so PHP not allow this
Change
To