Skip to content

Adapters rely on unset() of Reflection $name/$class, which php-src calls undefined behaviour #1589

Closed as not planned

Description

@lazerg

Hi,

I have an open php-src PR, php/php-src#24153, that makes the $name and $class properties of Reflection objects throw a ReflectionException on compound assignment, ++/-- and by-reference writes. Plain assignment already throws today. It targets master only.

The PR leaves unset() alone, so nothing changes for BetterReflection yet. But the adapters unset these properties in their constructors and serve them through __get, for example:

The same pattern is in ReflectionMethod, ReflectionClassConstant, ReflectionFunction, ReflectionParameter, ReflectionAttribute, ReflectionObject, ReflectionEnum and the enum case adapters.

During review, ndossche mentioned that BetterReflection depends on this, and kamil-tekiela replied that unsetting these properties is undefined behaviour and BetterReflection should move away from it. So a later php-src change may restrict unset() as well, and these constructors would then fail.

Opening this so you hear about it early. If you want to move the adapters off this trick, I'm happy to help with a PR.

Activity

  1. kukulich commented on Oct 18, 2026

    @kukulich
    Collaborator

    @lazerg Thank you for the info.

    The reason fot the use is descripted here: #673

  2. Ocramius commented on Oct 18, 2026

    @Ocramius
    Member

    kamil-tekiela replied that unsetting these properties is undefined behaviour

    No, it is well defined behavior, for which I introduced tests in PHP-SRC over a decade ago.

    Additionally, unset() behavior is regularly discussed on RFCs pertinent to property access logic.

  3. Ocramius commented on Oct 18, 2026

    @Ocramius
    Member

    Note: it may be possible to try and use PHP 8.4 proxies to work around the current logic, but it's just experimentation, and there's no clear path forward known upfront

  4. lazerg commented on Oct 19, 2026

    @lazerg
    Author

    Closing this. The php-src PR that prompted it is closed, so nothing changes for BetterReflection. Sorry for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions