Skip to content

Incorrect check implode() function for 8.0-8.4 #12079

@dbannik

Description

@dbannik

Bug report

PHP 8.0 - 8.4

<?php declare(strict_types = 1);

/**
 * @return string[]|null
 */
function getData(): ?array
{
    if (time() > 113) {
        return null;
    }

    return [''];
}

$list = getData();

echo implode(',', $list);
Fatal error: Uncaught TypeError: implode(): Argument #1 ($array) must be of type array, string given in /opt/scratches/scratch_182.php:17
Stack trace:
#0 /opt/scratches/scratch_182.php(17): implode(',', NULL)
#1 {main}
  thrown in /opt/scratches/scratch_182.php on line 17

Code snippet that reproduces the problem

https://phpstan.org/r/7bb01c8a-5d6d-4d5a-a6af-b760d13e0b8d

Expected output

image

Expected behavior with php 7.4

Parameter #2 $pieces of function implode expects array, array<string>|null given.

image

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

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions