Skip to content

fix: support PHP 8.4 property hooks - #62

Open
petrdobr wants to merge 1 commit into
Codeception:masterfrom
petrdobr:fix/php-84-property-hooks
Open

fix: support PHP 8.4 property hooks#62
petrdobr wants to merge 1 commit into
Codeception:masterfrom
petrdobr:fix/php-84-property-hooks

Conversation

@petrdobr

@petrdobr petrdobr commented Aug 2, 2026

Copy link
Copy Markdown

Summary

  • Support setting values for PHP 8.4 hooked properties redeclared by PHPUnit.
  • Preserve Stub::update() behavior by storing current values per mock.
  • Keep the existing reflection path for properties PHPUnit does not redeclare.
  • Add focused tests for backed, virtual, final-hook, and non-public
    properties.

Root cause

PHPUnit redeclares public hooked properties on the generated mock class so
their hooks can be configured.

Stub::bindParameters() used reflection to write the value to the property of
the original class. However, reading the property called the getter hook on
the generated mock class, where this value was not available.

The fix detects properties declared directly on the mock, configures their
getter once, and reads the current value from a WeakMap. Subsequent
Stub::update() calls replace the stored value without configuring the getter
again.

Properties that are not doubled by PHPUnit continue to use reflection.

The PHP 8.4-only test fixture uses an .inc extension and is loaded
conditionally so the test suite remains parseable on PHP 8.1–8.3.

Testing

  • Full test suite on PHP 8.4: 87 tests, 147 assertions
  • Full test suite on PHP 8.5: 87 tests, 147 assertions
  • Syntax checks on PHP 8.1 and PHP 8.3
  • composer validate
  • git diff --check

Fixes #61

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.

makeEmpty/make silently loses property values for PHP 8.4+ hooked properties

1 participant