Skip to content

False positive: strlen(ltrim(number_format())) #13784

@MartkCz

Description

@MartkCz

Bug report

PHPStan incorrectly reports a type error when using ltrim() with the result of number_format() inside strlen()

function ok(): int {
	return strlen(number_format(15, 0, '', ''));
}

/**
 * @param numeric-string $str
 */
function ok2(string $str): int {
	return strlen($str);
}

function fail(): int {
	return strlen(ltrim(number_format(15, 0, '', ''), '-'));
}

Error: Parameter #1 $string of function strlen expects string, numeric-string given.

Code snippet that reproduces the problem

https://phpstan.org/r/73c4b606-2bc7-4450-8c0d-3bdc7867dd75

Expected output

No error

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

No response

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