Skip to content

array_pop output should not be null given a full array #1722

@muglug

Description

@muglug

Found this while deciding whether to add similar functionality in another package.

/**
 * @param array<int, int> $arr
 */
function foo(array $arr) : int {
    $a = array_pop($arr);
	
    if ($arr) {
        return $a;
    }
	
    return 0;
}

Expected: no issue
Actual: Function foo() should return int but returns int|null
https://phpstan.org/r/693d212d-fec7-45fd-bce5-7bcf7c01afff

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions