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
{{ message }}
Repository navigation
use reflection to determine whether a global constant is deprecated #13570
I was looking into phpstan/phpstan#10662 and tried implementing detection of deprecated constants in PHPStan.
In the meantime I found that this information is also available on stubs phpdocs. This seems to work in my first prototype, so my initial feature request might no longer be necessary.
Even if you are able to find a workaround, I think a request makes sense in its own right. But it may need an RFC, perhaps only to cover some reasonable changes to ReflectionClassConstant (ie. how it should probably extend the new class).
See also the typed_constants RFC, which covered both class-level and global-level constants in reflection, but it seems the half supporting global constants never materialized. There have also been a few times a "ReflectionConstant" has been raised in the past, such as request #45569, but they all seemed to fixate on class constants only.
@mvorisek We already have ReflectionFunctionAbstract::isDeprecated() that only works for internal functions. For user constants, PHPStan can parse the phpDoc on its own.
Activity
damianwadley commentedon Mar 2, 2024
I don't see a (reasonable) way to get that information.
What do you need it for and how were you intending to use it?
staabm commentedon Mar 2, 2024
I was looking into phpstan/phpstan#10662 and tried implementing detection of deprecated constants in PHPStan.
In the meantime I found that this information is also available on stubs phpdocs. This seems to work in my first prototype, so my initial feature request might no longer be necessary.
I need todo a few more tests
damianwadley commentedon Mar 2, 2024
Even if you are able to find a workaround, I think a request makes sense in its own right. But it may need an RFC, perhaps only to cover some reasonable changes to ReflectionClassConstant (ie. how it should probably extend the new class).
See also the typed_constants RFC, which covered both class-level and global-level constants in reflection, but it seems the half supporting global constants never materialized. There have also been a few times a "ReflectionConstant" has been raised in the past, such as request #45569, but they all seemed to fixate on class constants only.
mvorisek commentedon Mar 2, 2024
you can set own error handler and detect raised warning - https://3v4l.org/M1cgh
what do you expect,
ReflectionConstant::isDeprecated()?how would that info be defineable for user constants?
iluuu1994 commentedon Mar 2, 2024
@mvorisek We already have
ReflectionFunctionAbstract::isDeprecated()that only works for internal functions. For user constants, PHPStan can parse the phpDoc on its own.staabm commentedon Mar 7, 2024
Note on my initial use-case:
PHPStan can/will report uses of deprecated constants based on phpdoc of php-stubs, jetbrains/stubs and other phpdocs starting with the next release
Implemented with phpstan/phpstan-src#2953
iluuu1994 commentedon Mar 11, 2024
I created a simple PR here: #13669
Implement reflection constant