feat(types): accept an array of any object at an array<Object> parameter#519
Open
chadmandoo wants to merge 1 commit into
Open
Conversation
PHP `array` parameters carry no element-type enforcement (there are no generics), so a declared `array<Object>` accepts an array of ANY object — a sibling or a subtype alike. Both sides share the same run representation (a boxed object pointer), so there is no element re-typing and the callee reads them through the class table regardless of the static element name. This is what a query-builder-style `withConditions(array $conditions)` needs when one call passes `array<QueryCondition>` and another `array<CompoundCondition>` (two concrete types implementing different interfaces), matching the docblock `list<QueryConditionInterface|CompoundConditionInterface>`. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
chadmandoo
added a commit
to chadmandoo/elephc
that referenced
this pull request
Jul 10, 2026
Survey-driven object/Mixed covariance at callback + interface boundaries (85% → 88%, 262 → 269/307). illegalstudio#470 (mixed/union arg boundary) already landed in 5052070; this completes the family: - ARRAY-CALLBACK OBJECT/MIXED ELEMENTS (illegalstudio#519 / EC-28b): array_map fabricated an IntLiteral dummy for non-scalar elements, so a typed callback (`fn (FieldDescriptor $f) => ...`) over a `list<FieldDescriptor>` failed "expects Object, got Int". array_map now routes through the object-aware comparator_dummy_arg_for_elem (synthetic-var + env binding), and that helper gains a Mixed arm — a bare `array` element infers as Mixed (phpdoc generics aren't enforced on the PHP `array` type), and Mixed accepts any declared parameter at the runtime-enforced boundary. usort/uasort widen their element gate from Object to Object|Mixed so the same typed-comparator shape checks. Clears the array_map/usort/uasort `callback parameter expects Object, got Int` family (8). - INTERFACE COVARIANT SELF-RETURN (#547 / EC-53): a `withX(): static`/self implementation of an interface-typed return (PSR-7 immutability methods) cannot go through type_accepts — the class is not yet registered mid-schema. Accept it from the facts at hand (this validation IS the proof the class implements the interface). Clears FileResponse et al. `withStatus incompatible return type` (3). Co-Authored-By: Claude Opus 4.8 <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.
What
PHP
arrayparameters carry no element-type enforcement (there are no generics), so a declaredarray<Object>should accept an array of any object — a sibling or a subtype alike.Previously rejected (two concrete types implementing different interfaces, passed to the same
arrayparam):How
In
type_accepts, theArray(expected_elem)arm now also accepts anArray(actual_elem)when both element types are objects. Both sides share the same run representation (a boxed object pointer), so there is no element re-typing — the callee reads elements through the class table regardless of the static element name.Test
test_array_element_object_sibling_covariance_at_param— awithConditions-style builder passing an array of a sibling concrete object, byte-parity vs PHP 8.5.🤖 Generated with Claude Code