Do not let placeholder members of intersection members override declared members - #6537
Merged
Merged
Conversation
…red methods
`MixedType` (and so `T of mixed`) answers `hasMethod()` with yes for every
method name and describes it with a `DummyMethodReflection` - declared on
`stdClass`, with a variadic signature that accepts anything.
`IntersectionType::getUnresolvedMethodPrototype()` merged that placeholder
with the method declared by another member, so on `T&Foo` the combined
method could pick the placeholder. Since `IntersectionTypeMethodReflection`
prefers a variadic signature, it always did: `getDeclaringClass()` returned
`stdClass` and `$x->bar(...)` lost its parameters.
phpstan-symfony's `RequestTypeSpecifyingExtension` looks up `getSession()`
on the declaring class of `hasSession()` and crashed on
`static::callback(function (Request $request) { return $request->hasSession() && ...; })`,
where the closure parameter is `CallbackInput&Request` while PHPUnit's
`callback()` template is being inferred.
Placeholder methods are now used only when no member declares the method.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NBzALCg92yf3LXFxxNBzoY
…clared properties Same as for methods: on `T&Foo`, the `DummyPropertyReflection` that `T of mixed` answers every property with was merged with `Foo`'s property and, being first, provided the declaring class - errors talked about `stdClass::$prop`. Placeholder properties are now used only when no member declares the property. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NBzALCg92yf3LXFxxNBzoY
…lared constants `IntersectionType::getConstant()` returned the constant of the first member answering `hasConstant()` with yes. `T of mixed` does so for every name with a `DummyClassConstantReflection` declared on `stdClass`, so on `T&Foo` the result depended on the order of the members. Placeholder constants are now used only when no member declares the constant. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NBzALCg92yf3LXFxxNBzoY
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.
MixedType- and soT of mixed- answershasMethod(),hasProperty()andhasConstant()with yes for every name and describes the member with aDummy*Reflectionplaceholder declared onstdClass.IntersectionTypemerged those placeholders with the members declared by the other intersected types, so onT&Foo:IntersectionTypeMethodReflectionprefers a variadic signature, so the placeholder (a variadicTrivialParametersAcceptor) always won -getDeclaringClass()returnedstdClassand$x->bar(...)lost its parametersstdClass::$propgetConstant()returned the placeholder when the mixed member came firstPlaceholders are now used only when no member declares the member.
The method part fixes the shopware/shopware integration test, red since 857a5f4 (2026-09-17): phpstan-symfony's
RequestTypeSpecifyingExtensioncalls$methodReflection->getDeclaringClass()->getNativeMethod('getSession')and crashed with "Method getSession() was not found in reflection of class stdClass" onwhere the closure parameter is
CallbackInput&Requestwhile PHPUnit'scallback()template is being inferred.On 2.3.x,
IntersectionTypeis shadowed byturbo-ext/src/IntersectionType.cpp(unresolvedPrototype(),getConstant()), so the merge-up needs the same change there.🤖 Generated with Claude Code
https://claude.ai/code/session_01NBzALCg92yf3LXFxxNBzoY