Skip to content

array_key_exists does not mark offset on superglobal as existing with reportPossiblyNonexistentGeneralArrayOffset #11447

@ManuelHu

Description

@ManuelHu

Bug report

This is only a problem with reportPossiblyNonexistentGeneralArrayOffset, so it cannot be reproduced in the playground.

Short reproducer (not some production code, of course :-):

\assert( \array_key_exists( 'key1', $_GET ) && \is_numeric( $_GET['key1'] ) );
\assert( isset( $_GET['key2'] ) && \is_numeric( $_GET['key2'] ) );

reports Offset 'key1' might not exist on array. on the first line. Swapping array_key_exists with isset does prevent the error though.


Interestingly,

$arr = $_GET;
\assert( \array_key_exists( 'key1', $arr ) && \is_numeric( $arr['key1'] ) );
\assert( isset( $arr['key2'] ) && \is_numeric( $arr['key2'] ) );

does not report any errors. So this problem appears to be limited to directly used superglobal arrays...

Code snippet that reproduces the problem

No response

Expected output

No error

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

PHPStan helps me a lot to keep out application working ;-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions