PHP refuses isset() on a function call or expression
isset() 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.
Fix it fast
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/2Match what you see, then jump to its fix
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.phpConfirmed by php.net
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.phpConfirmed by php.net
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/ | head2Fix
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.phpConfirmed by php.net
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
Android gets HTML instead of JSON from a PHP API
org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
The response body is not JSON.
2 causes, each with a fixBack 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 fixBack end
Apache returns 500 with Premature end of script headers
500 Internal Server Error
Apache ran your script, but the script printed no valid HTTP header before its output.
3 causes, each with a fixBack end
Apache returns 503 or 504 because PHP-FPM did not answer in time
Error dispatching request
Apache sent the request to PHP-FPM and gave up waiting.
3 causes, each with a fixBack end
AWS SDK for PHP cannot get credentials from the instance profile metadata server
Error retrieving credentials from the instance profile metadata server.
The SDK tries the EC2 instance metadata service when it has no valid credentials from anywhere earlier in its chain.
4 causes, each with a fixBack end
AWS SDK for PHP rejects requests: the signature is from the future
Signature not yet current: {date} is still later than {date}
AWS compares the timestamp in your signed request with its own clock.
2 causes, each with a fix