Skip to content

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

Closed
phpstan/phpstan-src
#4550

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

Activity

  1. VincentLanglet commented on Nov 11, 2025

    @VincentLanglet
    Contributor

    Should be solved with phpstan/phpstan-src#4550

  2. github-actions commented on Jan 6, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  3. locked as resolved and limited conversation to collaborators on Jan 6, 2026
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