Skip to content

PHPStan do not understand LABEL and GOTO #7711

@bckp

Description

@bckp

Bug report

PHPStan do not understand GOTO and LABEL, if you put them into code, PHPStan just ignore them instead of treating them as loop.

<?php declare(strict_types = 1);

/** @return int[]|null */
function getData(): ?array {
	return rand(0,1) ? [1,3,5] : null;
}

TEST:
$data = getData();
if (!$data) {
	goto TEST;
}

foreach ($data as $item) {
	echo $item;
}

Code snippet that reproduces the problem

https://phpstan.org/r/8c8e0d6d-60ef-4f7a-8dd1-8cb3c2916428

Expected output

No error should be found, as variable can contain only array at this point

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

Yeah, every day

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions