Skip to content

Offset 'error_subm_count' on non-empty-array in isset() always exists and is not nullable. #12771

@kamil-tekiela

Description

@kamil-tekiela

Bug report

One of the recent releases broke the check and now PHPStan reports that isset is redundant when it really isn't.

<?php

declare(strict_types=1);

final class ErrorReportController
{

    public function __invoke(ServerRequest $request)
    {
                if (
                    isset($_SESSION['prev_error_subm_time'], $_SESSION['error_subm_count'])
                    && $_SESSION['error_subm_count'] >= 3
                    && ($_SESSION['prev_error_subm_time'] - time()) <= 3000
                ) {
                    $_SESSION['error_subm_count'] = 0;
                    $_SESSION['prev_errors'] = '';
                } else {
                    $_SESSION['prev_error_subm_time'] = time();
                    $_SESSION['error_subm_count'] = isset($_SESSION['error_subm_count'])
                        ? $_SESSION['error_subm_count'] + 1
                        : 0;
                }
            
    }
}

Offset 'error_subm_count' on non-empty-array in isset() always exists and is not nullable.

Code snippet that reproduces the problem

https://phpstan.org/r/1a948bae-f71e-4886-a376-1d2aadd11b03

Expected output

There should be no warning about the offset.

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