Fix autoloader priority to prevent loading old framework classes from packages#6243
Draft
Fix autoloader priority to prevent loading old framework classes from packages#6243
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix error in readme generation workflow
Initialize $hook property in RootCommand constructor
Feb 14, 2026
This comment was marked as resolved.
This comment was marked as resolved.
…ages Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
Copilot
AI
changed the title
Initialize $hook property in RootCommand constructor
Fix autoloader priority to prevent loading old framework classes from packages
Feb 15, 2026
This comment was marked as resolved.
This comment was marked as resolved.
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
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.
The readme generation workflow fails because the autoloader loads old framework classes from package vendor directories instead of from the WP-CLI phar.
Root Cause
When WP-CLI runs from a phar and loads packages (e.g.,
scaffold-package-command), those packages may have their ownvendor/wp-cli/wp-clidirectory with old framework code. The autoloader registration order causes the issue:This results in old framework classes from package vendor directories being loaded instead of from the phar, leading to errors like "Call to undefined method WP_CLI\Dispatcher\RootCommand::get_hook()".
Changes
Autoloader Priority Fix (Primary)
Autoloader::register(): Added optional$prependparameter to support prepending the autoloader to the queueIncludeFrameworkAutoloader: Now calls$autoloader->register(true)to prepend the framework autoloaderThis ensures framework classes from the phar are always loaded first, even when packages have old wp-cli/wp-cli versions in their vendor directories.
Backward Compatibility Fix
$hook = ''inRootCommand::__construct(): Ensures backward compatibility for any code that might instantiate RootCommand directly or when older framework versions are temporarily loadedTest Coverage
features/autoloader-priority.feature: Comprehensive Behat tests with 3 scenarios to verify the fix:Testing
wp cli cmd-dumpworks correctlyThe fix properly addresses the autoloader conflict, ensuring that framework classes from the phar are always loaded first, regardless of what packages have in their vendor directories. The new tests prevent regressions by simulating real-world scenarios where packages might have outdated wp-cli/wp-cli dependencies.
Original prompt
This section details on the original issue you should resolve
<issue_title>Error in readme generation workflow</issue_title>
<issue_description>## Bug Report
Describe the current, buggy behavior
https://github.com/wp-cli/language-command/actions/runs/9379802233/job/25825470872#step:12:114
Error:
Describe what you would expect as the correct outcome
Generate readme correctly
Let us know what environment you are running this on
</issue_description>
Comments on the Issue (you are @copilot in this section)
@swissspidy Previous lengthy discussion about this:It's not isolated to this package alone. Basically all packages are affected.
It seemed like an autoloader issue to me.
The readme generation workflow basically does this:
wp package install "wp-cli/scaffold-package-command:^2"Now,
scaffold-package-commandrequires framework version 2.11.x, which was done in wp-cli/scaffold-package-command#243. And the WP-CLI nightly phar also requires framework version 2.11.xHowever, this particular command here does not.
So while in theory you would think the WP-CLI Phar loads the correct framework version, for some reason it loads classes from
language-command/vendor/wp-cli/wp-cli/..., which is the old version.That doesn't really make sense to me. Why is the Phar loading stuff from the current directory?
@schlessera Could you please enlighten us?</comment_new>
<comment_new>@BrianHenryIE
Is this happening only on GitHub or is it reproducible locally?
I had a very similar problem recently and came across others with also very similar problems: InterNACHI/modular#92 (comment)
I wouldn't be surprised if this is a Composer / GitHub Actions issue that will be fixed without changes on our end.</comment_new>
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.