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 👍
Discussed in #9211
Originally posted by DJTommek April 19, 2023
Hello 👋,
I'm using PHP classes for storing configuration. Main
DefaultConfigis versioned and second classConfigis not versioned, where admin can alter some default configuration (eg change class constantAPI_KEYfromnullto somestring).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:
treatPhpDocTypesAsCertaindynamicConstantNames:It seems, that
dynamicConstantNamesworks only for one type, because if I change default value fromnullto empty string''and update code (https://phpstan.org/r/7e6bc8b4-ab43-423d-b181-f0bc08cf4c03), then PHPStan is happy (again, class constant must be set indynamicConstantNames).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 👍