Skip to content

Offset 'dirname' of pathinfo function not always exists #8033

@guvra

Description

@guvra

Bug report

When calling pathinfo on an empty string, the function returns an array with only 2 keys:

  • basename
  • filename

Example:

php -r 'var_dump(pathinfo(""));'
Command line code:1:
array(2) {
  'basename' =>
  string(0) ""
  'filename' =>
  string(0) ""
}

On the other hand, phpstan expects this array to always contain the "dirname" offset.
So phpstan throws an error if we check whether dirname exists or not:

Code snippet that reproduces the problem

https://phpstan.org/r/fa3b7db7-5ce8-41d0-a63f-73742025ea3d

Expected output

PHPStan shouldn't detect an issue when we test whether the dirname offset exists.

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