Compile Error: Cannot Use Isset() on the Result of an Expression

Compile Error: Cannot use isset() on the result of an expression

From documentation:

isset() only works with variables as passing anything else will result in a parse error.

You're not directly passing a variable to isset(). So you need to calculate the value first, assign it to a variable, and then pass that to isset().

For example, what you're doing at the moment is something like:

if(isset($something === false)) { } // throws a parse error, because $something === false is not a variable

What you need to do instead is:

$something = false;
if(isset($something)) { ... }

Fatal error: Cannot use isset() on the result of an expression

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:

//true if both are set
if(isset($size, $color)) {
$style = 'font-size : ' . $size . ';color:' . $color;
}else{
$style = '';
}

You can clean this up a little further by setting the default value first, thus avoiding the need for an else section:

$style = '';
if(isset($size, $color)) {
$style = 'font-size : ' . $size . ';color:' . $color;
}

You could even use a ternary, though some people find them harder to read:

$style = isset($size, $color) ? 'font-size : ' . $size . ';color:' . $color : '';

Fatal error: Cannot use isset, use null expression instead

if(isset($userEmail = $_POST["email"]) && $userEmail = $_POST["email"] != ""){

Here, you are assigning it to a variable and then checking isset all in a single call. Split it up into separate calls:

  • check if it is set
  • check if it is not an empty string
  • validate it against the built-in email validator
  • assign it to a variable

Likely should be

if(isset($_POST["email"]) && $_POST["email"] != "") {
if(filter_var($_POST["email"], FILTER_VALIDATE_EMAIL)) {
...
$userEmail = $_POST["email"];
...

isset() on the result of an expression

I'd use the null coalescing operator ?? (https://www.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.coalesce)

return [
'description' => $this->field($content, 'description') ?? '',
//...
];

Fatal error: Cannot use isset, use null expression

Do you mean

 if ( isset($_GET['reply_id'], $_GET['reply_user']) ) {
// code here
}

Fatal error in if stament

Just change the condition to:

if(isset($_REQUEST['userid']) && $_REQUEST['userid'] > $user_hack) 

isset tells is a variable is set, while this statement may be true or false, on which you cannot call isset function.

Until you check if(isset($_REQUEST['userid'])), you cannot assign it to $userid variable.



Related Topics



Leave a reply



Submit