Skip to content

Value of constant is assumed to never change #3291

@schlessera

Description

@schlessera

Bug report

I have an issue in my code where I think the main problem boils down to PHPStan always assuming that a constant will never change.

However, some constants do change depending on the environment the code is run in, like *_VERSION constants that PHP itself provides.

For example, doing a version_compare against LIBXML_DOTTED_VERSION produces errors because PHPStan just uses the value of the constant as provided by the PHP runtime it is currently run under and doing the calculation with that.

Code snippet that reproduces the problem

https://phpstan.org/r/23472ba5-5edd-48d8-8e57-c197312ea07b

Expected output

I expect PHPStan not to throw an error here, as the code will produce different results depending on which version of PHP it is being run on.

I think the value of a constant should only be directly used if it is defined within the actual codebase, not for any of the dependencies.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions