Skip to content

isset causes template type to be forgotten #12355

@ESG-BHannay

Description

@ESG-BHannay

Bug report

It seems that checking if an array key isset can affect the type of a variable outside the if block, even if that block is empty. This was noticed while checking an array where one key is a template, and the other is optional.

The intention was to construct an object from a deeply nested array, where the outer keys are common between multiple classes.

Code snippet that reproduces the problem

https://phpstan.org/r/74d76565-8cf6-4da7-ab53-59f289d04097

Expected output

No errors reported.

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

PHPStan was useful while refactoring some data structures. By checking types, it helped ensure no files were forgotten.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions