Skip to content

false positive when using SplQueue (and probably other Spl datastructures #9180

@npluis

Description

@npluis

Bug report

the value count() of SplQueue is not updated after a shift/pop so phpstan still assumes it's > 0

<?php

$queue = new SplQueue();

$queue->push(1);

if ($queue->count() > 0) {
    for ($i=0;$i<5;$i++) {
        while ($queue->count() > 0 && $value = $queue->shift()) {
            //do something with $value
        }
    }
}

https://phpstan.org/r/84059d16-0659-4b9e-9001-1a7148bc930e

Expected output

no errors

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

It makes me happy every day! (well at least after I solve all the issues it reports)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions