Skip to content

SimpleXmlElement is valid in intval #14136

Closed

Description

@robotomarvin

Bug report

Hi, I have found a small issue after upgrading to newest phpstan 2.1.39 (from 2.1.36), and got reported

Parameter #1 $value of function intval expects array|bool|float|int|resource|string|null, SimpleXMLElement given.

Even when official doc says

intval() should not be used on objects, as doing so will emit an E_WARNING level error and return 1.

it works without a warning and looks like a special case.

(https://3v4l.org/cOvks#v8.5.3)

Code snippet that reproduces the problem

https://phpstan.org/r/974d2e74-2e37-461b-814f-1a3d8d84b4a9

Expected output

No error reported

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

No response

Activity

  1. VincentLanglet commented on Feb 17, 2026

    @VincentLanglet
    Contributor

    NB you have no error with (int) https://phpstan.org/r/8111387c-a024-47ff-8e5d-ddacf8ef510b

    because it rely on toInt method in ObjectType
    https://github.com/phpstan/phpstan-src/blob/c2da2e89e611749d0d455133c1ec482ab936efc6/src/Type/ObjectType.php#L64

    but for intval, it's https://github.com/phpstan/phpstan-src/blob/c2da2e89e611749d0d455133c1ec482ab936efc6/resources/functionMap.php#L5078
    if you want to work on the PR.

    Other *val should be checked/updated.

    But since it's a special case which is not even documented, I'm not sure if we should add it...

  2. phpstan-bot commented on Feb 28, 2026

    @phpstan-bot
    Contributor

    Closed via merging phpstan/phpstan-src#5020

  3. github-actions commented on Apr 1, 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.

  4. locked as resolved and limited conversation to collaborators on Apr 1, 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