Confusing error message: Cannot use isset() on the result of an expression (you can use "null !== expression" instead)
Open
Nobody has claimed this yet.
Feature
Status: Needs Triage
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
Description
The following code:
<?php
class X {
const A = '1';
}
$c = 'b';
isset(X::{$c});
Resulted in this (valid) output:
atal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead)
but I cannot use null !== X::{$c}, which also yields a Fatal Error.
With a constant, this message should recommend using 'defined()' instead, or on top of the current recommendation.
PHP Version
Tested on PHP 8.5, but any version since 8.3
Operating System
Not applicable.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the PHP 8.5 example using a dynamic class constant with isset(), then trace the diagnostic that produces the suggested null comparison. Determine where the message can account for constants and recommend defined() instead; done means the diagnostic is accurate for this example and existing behavior remains covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100