Skip to content

Narrowed @param not respected #14968

Open

Description

@puggan

Bug report

I'm in the process of removing an old parameter, so I changed the type from ?string to null, to get a warning on all places I have not yet replaced it.

simplifed example:

/**
 * @param null $b
 */
function a(?string $b): void
{
	if ($b) echo $b;
}

a(null);
a('test');

Expected a('test'); to complain.

Code snippet that reproduces the problem

https://phpstan.org/r/6776f1bb-56ae-4516-b73c-71b643a36b1f

Expected output

Line 12 Parameter #1 $b of function a expects null, string given.

Did PHPStan help you today? Did it make you happy in any way?

Every day

Activity

  1. puggan commented on Jul 17, 2026

    @puggan
    Author

    workaround, setting the php-type to mixed, let the old code still work, while giving the errors I was looking for:
    https://phpstan.org/r/4b67a3e0-66ee-487f-9bb5-2a106cdb5afd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions