Skip to content

Arrays with 'index' as an element cause autoloader events #14514

@JulianCBC

Description

@JulianCBC

Bug report

A code snippet like:

<?php

throw new Exception("ERROR: " . 'index');

causes exceptions if run in a project with mikecao/flight version 1.3.9 (yes, this is an ancient version of the class)

composer.json:

{
    "name": "jcalaby/phpstan",
    "require": {
        "phpstan/phpstan": "^2.1",
        "mikecao/flight": "1.3.9"
    },
    "authors": [
        {
            "name": "Julian Calaby",
            "email": "example@example.com"
        }
    ]
}

Trace ends with an attempt to autoload "index", which includes "vendor/flight/index.php" which is a demo file that unconditionally includes the file containing the Flight class.

Crash is:

 -- ---------------------------------------------------------------------------------------------------------
     Error
 -- ---------------------------------------------------------------------------------------------------------
     Child process error (exit code 255): PHP Fatal error:  Cannot declare class Flight, because the name is
     already in use in /home/jcalaby/project/vendor/mikecao/flight/flight/Flight.php on line 53
     Fatal error: Cannot declare class Flight, because the name is already in use in
     /home/jcalaby/project/vendor/mikecao/flight/flight/Flight.php on line 53
      while running parallel worker
 -- ---------------------------------------------------------------------------------------------------------

Code snippet that reproduces the problem

See this repository: https://github.com/JulianCBC/phpstan-index-repro

Expected output

No errors reported at level 0.

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

It helped me very quickly throw together a Rector class that cleaned up about 1500 lines of dead code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions