php / php/php-src

Confusing error message: Cannot use isset() on the result of an expression (you can use "null !== expression" instead)

Open
#21,507 1 comment 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.