🌐 US-Proxy
class="logged-out env-production page-responsive" style="word-wrap: break-word;" >
Skip to content

\stdClass isset checks modify subsequent behaviour #2262

Description

@buffcode

Bug report

When checking any attribute on a \stdClass, any further checks on attributes will fail, even if they succeeded before.

Code snippet that reproduces the problem

https://phpstan.org/r/721592ed-f4d1-4bb1-a7f0-047bd2183a55

declare(strict_types=1);

/** @var \stdClass[] $items */
$items = [];

foreach ($items as $item) {
    foreach ($item->subItems as $subItem) {
        echo $subItem->_works;   // works
        echo $subItem->willFail; // works

        if (isset($subItem->someOtherAttribute)) {
            // also fails with explicit type-hint to mixed, object and \stdClass
            echo $subItem->willFail; // fails, worked before
        }
    }
}

Expected output

No error should occur, just like when accessing _works or the first willFail.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions