Skip to content

Wrong array.duplicateKey after update to 2.1.15 #13022

@olelis

Description

@olelis

Bug report

After updates to 2.1.15 (from 2.1.14), php started to report that following simplified code have errors.

Example code:

function test(RootClass $object): void
{

    $searchId = $object instanceof SomeClass ? 'uid' : 'aid';
    $targetId = $object instanceof SomeClass ? 'aid' : 'uid';

    $array =        [
            $searchId => $object->getId(), // Here we have an "error"
            $targetId => 'info',
        ];

    // sql()->insert('tablename', $array); - example how this will be used
}

Errors are:

  22     Array has 2 duplicate keys with value 'aid' ($searchId, $targetId).  
         🪪 array.duplicateKey                                                
  22     Array has 2 duplicate keys with value 'uid' ($searchId, $targetId).  
         🪪 array.duplicateKey        

In reality, it has no errors.
Please follow link to reproduce error

Code snippet that reproduces the problem

https://phpstan.org/r/48c58510-01e1-495c-9fc6-6e188d148189

Expected output

There should be no errors

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

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions