Commit 48a7bbe
Do not autoload a class whose name is an already defined function
AutoloadFunctionsSourceLocator runs the autoloaders collected from bootstrap
files to find a class, without first checking whether the name is already a
defined function. A catch-all bootstrap autoloader then resolves a name like
VeeWee\Xml\Dom\Builder\value to the file that defines the function and
plain-includes it. That file was already loaded once - veewee/xml ships one
function per PSR-4 path and requires it from its files-autoload bootstrap - so
the second include fatally redeclares the function and the worker dies with
"Cannot redeclare function ...".
The common real-world autoloader here is PHP_CodeSniffer's, loaded via
bootstrapFiles because the package ships no Composer autoload metadata; it falls
back to Composer's findFile() for any name and includes with a plain include.
The name is probed as a class and the file holds a function, so running the
autoloader cannot find a class there; it only re-includes the file. Return early
when the name is already a defined function, the same way the locator already
returns early for an existing class, interface or trait. A class that genuinely
exists under that name in another file is still found by the later source
locators in the chain.
Wrapping the autoloader call in FileReadTrapStreamWrapper (as AutoloadSourceLocator
does) was considered but is not viable here: these bootstrap autoloaders run for
real, and some read a file for its return value (a loader delegating via
"$loader = include ...; $loader->loadClass()") or write cache files, which the
trap breaks.
e2e/bug-14988 reproduces it: an unguarded one-function-per-file, a bootstrap that
requires it, and a catch-all autoloader shaped like PHP_CodeSniffer's. Before the
change the worker fatals with the redeclare; after it, analysis completes. It also
covers a class and a function that share a name in separate files (both reachable
only through that bootstrap autoloader, not Composer), asserting the class still
resolves.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent b88ca9c commit 48a7bbe
12 files changed
Lines changed: 157 additions & 0 deletions
File tree
- .github/workflows
- e2e/bug-14988
- classes
- pkg
- src
- src/Reflection/BetterReflection/SourceLocator
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
131 | 135 | | |
132 | 136 | | |
133 | 137 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
0 commit comments