Skip to content

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

Closed

Description

@staabm

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?

Activity

  1. damianwadley commented on Mar 2, 2024

    @damianwadley
    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?

  2. staabm commented on Mar 2, 2024

    @staabm
    ContributorAuthor

    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

  3. damianwadley commented on Mar 2, 2024

    @damianwadley
    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.

  4. mvorisek commented on Mar 2, 2024

    @mvorisek
    Contributor

    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?

  5. iluuu1994 commented on Mar 2, 2024

    @iluuu1994
    Member

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

  6. staabm commented on Mar 7, 2024

    @staabm
    ContributorAuthor

    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

  7. iluuu1994 commented on Mar 11, 2024

    @iluuu1994
    Member

    I created a simple PR here: #13669

  8. added a commit that references this issue on Apr 17, 2024
    e23440e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions