Skip to content

False-positive on strtolower() when explicit strings are required #6987

@Wirone

Description

@Wirone

Bug report

PHPStan 1.5.4 introduced some false-positive errors in our codebase related to strtolower usage and explicit phpDocs like @param 'foo'|'bar'.

Code snippet that reproduces the problem

https://phpstan.org/r/2f860fdb-4923-4467-ad04-e851c6666e6e
https://phpstan.org/r/bf565b4a-39e9-4e59-8e74-7d83d5a9a4eb (@puniserv's example)

<?php declare(strict_types = 1);

/**
 * @param 'foo'|'bar' $foo
 */
function foo(string $foo): void {
}

foo(strtolower('bar'));

Expected output

No error, since set of explicitly allowed non-empty strings is a subset of expected non-empty-string.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions