Skip to content

use reflection to determine whether a global constant is deprecated #13570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
staabm opened this issue Mar 2, 2024 · 7 comments
Closed

use reflection to determine whether a global constant is deprecated #13570

staabm opened this issue Mar 2, 2024 · 7 comments

Comments

@staabm
Copy link
Contributor

staabm commented Mar 2, 2024

Description

I did not found a way to determine whether a constant is deprecated.

https://3v4l.org/opYVk#v8.1.21

does the reflection extension miss someting like ReflectionConstant?

@damianwadley
Copy link
Member

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
Copy link
Contributor Author

staabm commented 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
Copy link
Member

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
Copy link
Contributor

mvorisek commented Mar 2, 2024

I did not found a way to determine whether a constant is deprecated.

you can set own error handler and detect raised warning - https://3v4l.org/M1cgh

use reflection to determine whether a global constant is deprecated

what do you expect, ReflectionConstant::isDeprecated()?

how would that info be defineable for user constants?

@iluuu1994
Copy link
Member

@mvorisek We already have ReflectionFunctionAbstract::isDeprecated() that only works for internal functions. For user constants, PHPStan can parse the phpDoc on its own.

@staabm
Copy link
Contributor Author

staabm commented 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 added a commit to iluuu1994/php-src that referenced this issue Mar 11, 2024
iluuu1994 added a commit to iluuu1994/php-src that referenced this issue Mar 11, 2024
@iluuu1994
Copy link
Member

I created a simple PR here: #13669

iluuu1994 added a commit to iluuu1994/php-src that referenced this issue Mar 20, 2024
iluuu1994 added a commit to iluuu1994/php-src that referenced this issue Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants