Guard iterator_to_array() against being declared twice - #7
Draft
Steveb-p wants to merge 1 commit into
Draft
Conversation
src/iterator_to_array.php is loaded eagerly through composer's "autoload.files", but it also sits
inside the directory "autoload.psr-4" maps Ibexa\PolyfillPhp82\ to. Anything that resolves
"Ibexa\PolyfillPhp82\iterator_to_array" as a *class* name therefore makes the autoloader include
the file a second time, and without a guard that's fatal:
PHP Fatal error: Cannot redeclare Ibexa\PolyfillPhp82\iterator_to_array()
(previously declared in .../src/iterator_to_array.php:18)
Static analysers probing an imported function are the common trigger. PHPStan hits it in any
package that writes `use function Ibexa\PolyfillPhp82\iterator_to_array;` -- it dies before
reporting anything, so the analysis job fails with an error that has nothing to do with the code
under test. ibexa/test-core is currently red on PHP 7.4 for exactly this reason.
Wrapping the declaration in function_exists() makes the second include a harmless no-op, which is
how symfony/polyfill handles its own function files. Added a regression test that requires the
file a second time; it reproduces the fatal above without this change.
Leaving the autoload.files / autoload.psr-4 overlap in place -- narrowing PSR-4 away from this
file would work too, but the guard is the smaller change and protects against any other path that
ends up including it twice.
Steveb-p
force-pushed
the
guard-against-double-declaration
branch
from
September 8, 2026 21:11
f5c1720 to
590fa30
Compare
Steveb-p
marked this pull request as ready for review
September 8, 2026 21:28
Steveb-p
added a commit
to ibexa/test-core
that referenced
this pull request
Sep 8, 2026
…82#7 PHPStan dies on PHP 7.4 before reporting anything -- "Cannot redeclare Ibexa\PolyfillPhp82\iterator_to_array() ... while running parallel worker" -- so this job fails on every PR against 4.6 regardless of contents. Points CI at the branch that guards the declaration. Must be removed before merging.
Steveb-p
added a commit
to ibexa/test-core
that referenced
this pull request
Sep 8, 2026
…82#7 PHPStan dies on PHP 7.4 before reporting anything -- "Cannot redeclare Ibexa\PolyfillPhp82\iterator_to_array() ... while running parallel worker" -- so this job fails on every PR against 4.6 regardless of contents. Points CI at the branch that guards the declaration. Must be removed before merging.
This was referenced Sep 8, 2026
Draft
Steveb-p
marked this pull request as draft
September 8, 2026 21:41
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related PRs:
Description:
src/iterator_to_array.phpis loaded eagerly through composer'sautoload.files, but it also sitsinside the directory
autoload.psr-4mapsIbexa\PolyfillPhp82\to. So anything resolvingIbexa\PolyfillPhp82\iterator_to_arrayas a class name makes the autoloader include the file asecond time, and without a guard that's fatal:
Static analysers probing an imported function are the common trigger. PHPStan hits it in any
package that writes
use function Ibexa\PolyfillPhp82\iterator_to_array;— it dies beforereporting anything, so the job fails with an error unrelated to the code under test.
ibexa/test-coreis currently red on PHP 7.4 for exactly this, on every PR against
4.6regardless of contents.Wrapping the declaration in
function_exists()makes the second include a harmless no-op, which ishow
symfony/polyfillhandles its own function files.testDeclarationFileCanBeLoadedTwicecoversit — I checked it reproduces the fatal above with the guard stashed, so it's a real regression test
rather than a green one.
I left the
autoload.files/autoload.psr-4overlap alone. Narrowing PSR-4 away from this filewould also fix it, but the guard is the smaller change and covers any other path that ends up
including the file twice.