Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Combiantion of dynamicConstantNames and null does not work #9218

@ondrejmirtes

Description

@ondrejmirtes

Discussed in #9211

Originally posted by DJTommek April 19, 2023
Hello 👋,
I'm using PHP classes for storing configuration. Main DefaultConfig is versioned and second class Config is not versioned, where admin can alter some default configuration (eg change class constant API_KEY from null to some string).

https://phpstan.org/r/b9d95a54-6b62-4446-bf0c-6d0ea53bcef0

Various places in my code fails on Strict comparison using === between string and null will always evaluate to false.

I don't know, how to deal with this problem. Tried:

  • updating treatPhpDocTypesAsCertain
  • adding constant(s) into dynamicConstantNames:
    dynamicConstantNames:
        - Config::*
        - DefaultConfig::*
        - Config::API_KEY
        - DefaultConfig::API_KEY

It seems, that dynamicConstantNames works only for one type, because if I change default value from null to empty string '' and update code (https://phpstan.org/r/7e6bc8b4-ab43-423d-b181-f0bc08cf4c03), then PHPStan is happy (again, class constant must be set in dynamicConstantNames).

Is that intended behavior? I kind of don't like this workaround, but I guess I don't have better alternative than rewrite it like so.

Thanks in advance 👍

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions