Skip to content

[TypeDeclaration] Ignore docblock-narrowed args in AddMethodCallBasedStrictParamTypeRector - #9048

Merged
TomasVotruba merged 2 commits into
mainfrom
method-call-param-type-no-doc-leak
Nov 23, 2026
Merged

TomasVotruba merged 2 commits into
mainfrom
method-call-param-type-no-doc-leak

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

AddMethodCallBasedStrictParamTypeRector reads the native type of call args, but for an untyped param with a @param docblock, PHPStan's native type picks up the docblock type after narrowing like isset($data['key']):

/**
 * @param array<string, mixed> $data
 */
public function runFirst($data)
{
    if (! isset($data['key'])) {
        throw new ShouldNotHappenException();
    }

    $this->process($data);
}

-private function process($data)
+private function process(array $data)

runFirst(new ArrayObject(['key' => 'value'])) worked before, and throws a TypeError after. Without the docblock or without the isset(), nothing changes.

Fix: in CallTypesResolver::resolveStrictArgValueType(), an arg that is a variable of an untyped param of the enclosing function with a @param type resolves to mixed. Untyped params with no docblock type (or @param mixed) are kept, so native narrowing like isset($data->type) -> object still works (has_property_type.php.inc).

The param_array_offset.php.inc fixture encoded the bug, so it's now skip_param_array_offset.php.inc.

@TomasVotruba
TomasVotruba merged commit 65c4a0c into main Nov 23, 2026
51 checks passed
@TomasVotruba
TomasVotruba deleted the method-call-param-type-no-doc-leak branch November 23, 2026 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants