Skip to content

Make isInitialized() reject an absent property with InvalidArgumentException - #365

Open
lenamonj wants to merge 1 commit into
webmozarts:masterfrom
lenamonj:fix-is-initialized-absent-property
Open

Make isInitialized() reject an absent property with InvalidArgumentException#365
lenamonj wants to merge 1 commit into
webmozarts:masterfrom
lenamonj:fix-is-initialized-absent-property

Conversation

@lenamonj

@lenamonj lenamonj commented Sep 1, 2026

Copy link
Copy Markdown

Assert::isInitialized(json_decode('{}'), 'name') throws ReflectionException: Property stdClass::$name does not exist instead of InvalidArgumentException, so a caller catching the documented type does not catch it. Same for any object lacking the property (ArrayObject, 'storage').

Cause: a ReflectionProperty is built before anything is checked.

Change: test property_exists() first. The accepted set is unchanged (property_exists is true for declared and dynamic properties alike); only the exception type on the absent-property path changes. Two rows added to the shared provider.

Verified: composer run test 4920 tests green on PHP 8.4 (both rows fail with the ReflectionException before the fix), cs-check and static-analysis clean.

Found by an automated code-review loop I run; the fix and this description were prepared with Claude and verified by hand.

…ption

isInitialized() built a ReflectionProperty before checking anything, so an
object that lacks the property escaped a raw ReflectionException instead of
the InvalidArgumentException every assertion promises. Test property_exists
first; the accepted set is unchanged since it is true for declared and
dynamic properties alike.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@zerkms

zerkms commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

the fix and this description were prepared with Claude

this world is cursed: now 1 function call need to be ai-slopped 🤦

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.

2 participants