Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

PHP refuses isset() on a function call or expression

Errorisset() rejects a function call such as isset(trim($name))

Short answer

isset() is a language construct that accepts only variables, array elements and properties, so a function call or other expression inside it is rejected when PHP compiles the file. Store the value in a variable first, compare with null !==, or use the ?? operator.

  • Applies to PHP 8.3, PHP 8.4
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find every isset( whose argument contains a parenthesis, an operator or a constant. Those lines are the ones PHP refuses.

    grep -rnE "isset\([^)$]*\(" src/
  2. 2Match what you see, then jump to its fix

    1. 1isset($obj->getValue()) or isset(trim($name))A function or method call is inside isset()Fix
    2. 2isset(SOME_CONSTANT)isset() is used on a constantFix
    3. 3isset(...) ? ... : ... repeated around a function resultA default value is wanted, so ?? is the right toolFix

What does the error look like?

  • isset() rejects a function call such as isset(trim($name))
  • The page shows a parse or fatal error before any code runs

Cause 1 of 3

A function or method call is inside isset()

1Check

The manual says isset() only works with variables: passing anything else is an error.

grep -rn "isset(.*->.*()" src/

2Fix

Compare the result with null, or assign it to a variable and test the variable.

if (null !== $obj->getValue()) { /* ... */ }

$value = $obj->getValue();
if (isset($value)) { /* ... */ }

3Verify

The file compiles and the branch behaves as before.

php -l src/Service.php

Confirmed by php.net

Did this fix it?

Cause 2 of 3

isset() is used on a constant

1Check

The manual says to use defined() for constants.

grep -rnE "isset\([A-Z_]+\)" src/

2Fix

Use defined() for a constant.

if (defined('APP_DEBUG')) { /* ... */ }

3Verify

php -l passes.

php -l src/config.php

Confirmed by php.net

Did this fix it?

Cause 3 of 3

A default value is wanted, so ?? is the right tool

1Check

The null coalescing operator takes expressions on both sides, evaluates to the right side when the left is null, and gives no notice for a missing key.

grep -rn "isset(" src/ | head

2Fix

Replace the isset ternary with ??.

$timeout = getConfig('timeout') ?? '30';
$action = $_POST['action'] ?? 'default';

3Verify

The code runs with and without the key present.

php -l src/Service.php

Confirmed by php.net

Did this fix it?

How do I stop it coming back?

  • Run php -l on changed files before deploying.
  • Treat isset() as a check on a variable's existence, not on a value you compute.
  • Use array_key_exists() when a key holding null must count as present.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

Apache returns 403 when a URL contains %3F

a request like /page%3Fname=test is refused while /page?name=test works

Recent Apache httpd blocks a rewrite when the request contains an encoded question mark (%3F) and the rewritten target has a literal ?.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.