fix: pass null to ReflectionProperty::setValue() for static Assert::$count - #253
Open
gherrink wants to merge 1 commit into
Open
fix: pass null to ReflectionProperty::setValue() for static Assert::$count#253gherrink wants to merge 1 commit into
gherrink wants to merge 1 commit into
Conversation
…count
Execution::resetAssertions() passed Assert::class as the first argument of
ReflectionProperty::setValue(). For a static property PHP 8.3 deprecates any
first argument that is not null or an object:
Calling ReflectionProperty::setValue() with a 1st argument which is not
null or an object is deprecated
It fires whenever an assertion retries, so it attaches to an arbitrary test --
usually a slow one -- and labels it DEPRECATED while the run still exits 0.
The single-argument form setValue($value) is deprecated as well on 8.4
("Calling ReflectionProperty::setValue() with a single argument is
deprecated"), so null as the first argument is the only spelling that is clean.
The @phpstan-ignore-next-line has to go with it: phpstan.neon sets
reportUnmatchedIgnoredErrors: true, and the corrected call raises nothing for it
to match.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Forward-port of #244 to
5.x. That PR targets4.xonly, and its author offered to port it here — this is that port. Happy to close either if you would rather take one.The problem
Execution::resetAssertions()passesAssert::classas the first argument toReflectionProperty::setValue().Assert::$countis static, and PHP 8.3 deprecates any first argument that is notnullor an object:It fires whenever an assertion retries, so it attaches to an arbitrary test — usually a slow one — and labels it
DEPRECATEDwhile the run still exits 0. On PHP 9 the call stops working altogether.Why
nulland not the single-argument formsetValue($value)looks like the tidier fix, but it is deprecated too on 8.4. Measured on PHP 8.4.23:setValue(Assert::class, $n)Calling ReflectionProperty::setValue() with a 1st argument which is not null or an object is deprecatedsetValue(null, $n)setValue($n)Calling ReflectionProperty::setValue() with a single argument is deprecatedSo
nullas the first argument is the only spelling that raises nothing.Why the ignore comment goes too
phpstan.neonsetsreportUnmatchedIgnoredErrors: true, so leaving// @phpstan-ignore-next-lineon the corrected call fails the build.composer test:typesis green with it removed (level max,--memory-limit=2G; the default 128M crashes a parallel worker on this machine).Checked
composer test:types— no errors.composer test:lint—rector --dry-runreportssrc/Support/Screenshot.php:42, which reproduces identically on unmodified5.x. Not from this change.v5.0.1in a real project's browser suite: theDEPRECATEDlabel disappears and the run is otherwise identical — 53 passed, 106 assertions, before and after.