You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When creating a constant using the Safe\define() function, and the value of the constant is an enum, PHPStan seems unable to understand the constant as a dynamic constant.
<?phpusefunctionSafe\define;
enum TestEnum: string{
case Foo = "foo";
case Bar = "bar";
}
/** @varstring $fooConfig */$fooConfig = get_cfg_var('app.foo');
// Try to use Safe\define() with an enumdefine('FOO_CONST', TestEnum::tryFrom($fooConfig) ?? TestEnum::Foo); // Safe\define()if(FOO_CONST == TestEnum::Foo){ // Error: PHPStan emits: If condition is always true.print('Foo');
}
// Try to use \define() with an enum\define('BAR_CONST', TestEnum::tryFrom($fooConfig) ?? TestEnum::Foo); // \define()if(BAR_CONST == TestEnum::Foo){ // OK, got expected output - PHPStan emits: Function define is unsafe to use.print('Foo');
}
?>
The text was updated successfully, but these errors were encountered:
Environment
PHP version: 8.1.28
PHPStan version: 1.11.1
Safe version: 2.5.0
PHPStan Safe Rule version: 1.2.0
Description of problem
When creating a constant using the
Safe\define()
function, and the value of the constant is an enum, PHPStan seems unable to understand the constant as a dynamic constant.Example
PHPStan configuration
PHP
The text was updated successfully, but these errors were encountered: