Skip to content

Appending to empty arrays creates a mixed array #747

@muglug

Description

@muglug
/** @return int[] */
function foo() : array {
  $arr = [];
  $arr[] = new stdClass;
  return $arr;
}

https://phpstan.org/r/ea6c23403e832684333cea82e06c7d04

The return type int[] is wrong here, but PHPStan cannot see it.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions