-
Notifications
You must be signed in to change notification settings - Fork 11.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Breaking change in registration of inherited providers #51739
Comments
Hey there, thanks for reporting this issue. We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as one separate commit on the main/master branch and share the repository here? Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up.
Do not amend and create a separate commit with your custom changes. After you've posted the repository, we'll try to reproduce the issue. Thanks! |
I don't believe this is the correct way and is never meant to be supported, service providers should be registered via |
Hi Crynobone, Affected application uses separate custom package and registered "CommonServiceProvider" (using app.providers). In case you want to check it, I've prepared the repository, that helps to reproduce it: Thx! |
The correct way to solve this is actually:
<?php
return [
App\Providers\AppServiceProvider::class,
- App\Providers\CommonServiceProvider::class,
];
'providers' => Illuminate\Support\ServiceProvider::defaultProviders()
->replace([
'Illuminate\Database\MigrationServiceProvider' => 'App\Providers\CustomMigrationServiceProvider',
])
->toArray(), |
Laravel Version
11.9
PHP Version
8.2.13
Database Driver & Version
No response
Description
Before v11.9, the registration of services paid attention to instance of service (using instanceof) and avoided the registration if "similar" class was already registered. With v11.9 it matches exactly using fully qualified name of the class.
php:instanceof - instanceof can also be used to determine whether a variable is an instantiated object of a class that inherits from a parent class.
Example:
let define CustomMigrationServiceProvider extends Illuminate\Database\MigrationServiceProvider.
and register the provider.
The order of registration during booting of an application is exactly the same for all 11 laravel versions:
but
Reason for the breaking change:
https://github.com/laravel/framework/compare/ceb892..2fd3a25#diff-0a80606049a107748776bea5151a61fbec2afefe3361c340a5de9c8c1ccdf9c8
** \Illuminate\Foundation\Application::markAsRegistered pushed the registered service onto the end of list
** \Illuminate\Foundation\Application::getProvider used getProviders (iterates over the list using instanceof)
** \Illuminate\Foundation\Application::markAsRegistered set the registered service in the list using fully qualified name (key => value)
** \Illuminate\Foundation\Application::getProvider access the registered service directly using fully qualified name
Steps To Reproduce
The text was updated successfully, but these errors were encountered: