Skip to content

False positive with array_combine #1580

@josephzidell

Description

@josephzidell

I am getting a false positive when trying to add array with a combined array.

Here is the code with a link https://phpstan.org/r/e906bbea4b53a52babf61ce1deb1aa05

<?php declare(strict_types = 1);

$a1 = ['a', 'b', 'c'];
$a2 = [1, 2, 3];
$a3 = ['d', 'e', 'f'];

$combined = array_combine($a1, $a2);
$added = $a3 + $combined;

And the error message is:

Binary operation "+" between array('d', 'e', 'f') and array|false results in an error.

In the docs for array_combine(), it says

Returns the combined array, FALSE if the number of elements for each array isn't equal. 

In this case, the number of elements are clearly the same. What do you suggest?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions