Skip to content

Fix PHP 8.3/8.5 deprecations in TestCaseTrait reflection helpers - #33

Merged
remyperona merged 2 commits into
developfrom
fix/php-deprecations
Jul 30, 2026
Merged

Fix PHP 8.3/8.5 deprecations in TestCaseTrait reflection helpers#33
remyperona merged 2 commits into
developfrom
fix/php-deprecations

Conversation

@remyperona

@remyperona remyperona commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Fixes #29

Changes

setValue() on static properties. set_reflective_property() forwarded $instance straight to ReflectionProperty::setValue(), but callers pass a class name when targeting a static property. Static properties are now set with an explicit null target:

if ( $property->isStatic() ) {
    $property->setValue( null, $value );
} else {
    $property->setValue( $instance, $value );
}

setAccessible(). No-op since PHP 8.1, deprecated as of 8.5, but still required on 7.4/8.0. All four call sites now route through a private set_reflector_accessible() helper that returns early when PHP_VERSION_ID >= 80100.

getNonPublicPropertyValue() picked up an isStatic() check so it no longer relies on the object argument being silently ignored for static properties. Behaviour is unchanged.

The library keeps its >=7.4 compatibility — the version guard is the reason setAccessible() is kept rather than deleted.

Testing

  • Both deprecations reproduced verbatim against the pre-fix code on 8.3 and 8.5, confirming the right code paths were exercised.
  • New Tests/Unit/testTestCaseTrait.php covers instance/static property set+get (via both a class name and an instance), non-public method invocation, and asserts no E_DEPRECATED is emitted. That last test fails against the old implementation on both 8.3 and 8.5, so it is a real guard.

Notes for the reviewer

  • Pre-existing and out of scope: get_reflective_property() uses ReflectionClass::getProperty(), which does not find a private property declared on a parent class.

🤖 Generated with Claude Code

ReflectionProperty::setValue() emits a deprecation as of PHP 8.3 when its
first argument is neither null nor an object, which happened whenever
set_reflective_property() targeted a static property (the caller passes a
class name). Static properties are now set with an explicit null target.

Reflection*::setAccessible() has no effect since PHP 8.1 and is deprecated
as of PHP 8.5. The calls are now routed through a helper that skips them on
PHP 8.1+, keeping them for the still-supported PHP 7.4 and 8.0.

Adds a regression test covering both helpers plus a deprecation-free
assertion. Verified on PHP 7.4, 8.0, 8.1, 8.2, 8.3, 8.4 and 8.5.

Fixes #29

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@remyperona remyperona self-assigned this Jul 30, 2026
@remyperona remyperona linked an issue Jul 30, 2026 that may be closed by this pull request
Covers the version that surfaced the setAccessible() deprecation in #29, so
the regression test in testTestCaseTrait.php guards it going forward.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@remyperona
remyperona merged commit cbad06c into develop Jul 30, 2026
7 checks passed
@remyperona
remyperona deleted the fix/php-deprecations branch July 30, 2026 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PHP Deprecated with 8.3/8.5

1 participant