DEVSENSE / phptools-docs

PHP Tools public content
Apache License 2.0
83 stars 10 forks source link

Calling `is_numeric` on string converts variable type to float/int #634

Closed vitkutny closed 3 months ago

vitkutny commented 3 months ago

Calling is_numeric on string converts variable type to float/int. It should remain string – specificaly can be changed to numeric-string similar to phpstan behaviour https://phpstan.org/writing-php-code/phpdoc-types#other-advanced-string-types

Code with error:


$string = '0123';

if (is_numeric($string)) {
    echo trim($string, '0'); # Argument '1' passed to trim() is expected to be of type string, float|int given – PHP0406
}

Expected result: no error

jakubmisek commented 3 months ago

thanks, this inferring will be removed for now.