You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Method template K of key-of<T> is inferred as string instead of the literal key, so valid keys fail the upper bound #139
/** @template T of array<string, mixed> */
abstract class Base
{
/**
* @template K of key-of<T>
* @param K $key
*/
public function get(string $key): string { return $key; }
}
/** @extends Base<array{selectedMenu: string, readList: string}> */
final class Child extends Base {}
(new Child())->get('selectedMenu');
Expected: no error. 'selectedMenu' is a key of the array bound to T through @extends, so it satisfies key-of<T> (PHPStan accepts it).
Actual:
TypePHP\Exception\TypeError: Child::get(): Generic type argument string does not satisfy upper bound
key-of<array{selectedMenu: string, readList: string}> of template K
T is resolved correctly (the message shows the bound array). It looks like K is inferred from the native parameter type (string) rather than from the argument's literal value, and string is then checked against the key union.
Impact for us: ~830 reports per run on one module method (getConfiguration(string $type, ?string $key) with @template K of key-of<TConfigurationItem>), all on valid keys. We park it on our side until fixed.
Activity
rcalicdan commentedon Nov 25, 2026
@fdaviddpt Hello this is now resolved in v0.14.2