Skip to content

Accessing constants of a phantom classes #1555

@weirdan

Description

@weirdan

Psalm is fine with method calls on phantom classes (those asserted to exist with class_exists), but it thinks class does not exist when accessing a constant on those same classes. I'd expect them to be mixed (apart from ::class, which is always string containing the class name), but valid otherwise.

https://psalm.dev/r/9861da4b25

<?php
  if (class_exists('A') && method_exists('A', 'method')) {
     echo A::method();
     echo A::class;
     echo A::SOME_CONST;
  }

Expected: no issues
Actual:

Psalm output (using commit 8dda8a0): 

ERROR: UndefinedClass - 4:11 - Class or interface A does not exist

ERROR: UndefinedClass - 5:11 - Class or interface A does not exist

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions