Skip to content

[PHP8.6] ReflectionProperty::isReadable() / isWriteable() emulation #222

Closed

Description

@lisachenko

Part of epic #219.

Feature

PHP 8.6 adds scope-aware accessibility introspection to \ReflectionProperty:

  • isReadable(?string $scope = null): bool
  • isWriteable(?string $scope = null, ?object $object = null): bool

These answer whether a property can be read/written from a given scope, taking into account visibility, asymmetric visibility (private(set)/protected(set), PHP 8.4), readonly state (a readonly property is writeable only from the permitted scope and only while uninitialized on the given $object), virtual/hooked properties (get-only hooks are not writeable), and interface/abstract properties.

Scope

  • Implement both methods in src/ReflectionProperty.php statically from the AST where possible: visibility flags, set-visibility, readonly, hook presence (get/set), virtual properties.
  • The $object-dependent part of isWriteable() (readonly initialization state) requires a live object — fall back to native reflection via the existing initialization/fallback mechanism in that case.
  • Validate $scope semantics: null = global scope; class-name scope including inherited/subclass scope rules — match native behavior exactly.
  • Stubs covering: public/protected/private, asymmetric visibility, readonly (with and without default), hooked properties (get-only, set-only, both, virtual), promoted properties, interface abstract properties.
  • Parity tests guarded with PHP_VERSION_ID >= 80600; direct assertions for 8.5 runtime.
  • Exact final signatures/behavior must be verified against the 8.6 beta docs/implementation before coding.

Acceptance criteria

  • Full matrix of stub properties returns values matching native reflection on 8.6.
  • PHPUnit green on 8.5, PHPStan level 10 clean.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions