-
Notifications
You must be signed in to change notification settings - Fork 11k
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
Contextual binding resolved when it shouldn't be for LogManager #52480
Comments
Thank you for reporting this issue! As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub. If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team. Thank you! |
I think the issue is due to the Test: namespace App;
final class Test implements \JsonSerializable
{
- public function jsonSerialize()
+ public function jsonSerialize() : mixed
{
return [];
}
} |
@rust17 I know about this, because it triggers deprecation. But this is not root cause of issue - the issue here is bugged contextual binding and that's used when being in HandleExceptions context and/or using same alias for classes that are not compatible with each other. |
@crynobone I have question here, why there is |
The label is added because we'd appreciate any community effort here in getting this resolved. |
Laravel Version
11.20.0
PHP Version
8.3.9
Database Driver & Version
No response
Description
So currently there is an issue with contextual binding(LogManager is just example) and
Container::call()
method, but any alias that is pointing to two different not compatible with each other interfaces can cause this problem.Basically, we have an issue after upgrading to laravel 9(but also happens on 11) that when we have contextual binding for LoggerInterface::class, but deprecation log is happening there will be an exception triggered for that:
The reason is that both classes are aliased as
log
and laravel container when gettingLogManager
resolves it to aliaslog
and since there is contextual binding for it, it returns wrong instance, without channel method existing.I see this being solved by either stopping aliasing incompatible types with each other in the container or somehow resolving the correct type in the first place — don't use contextual binding when it shouldn't be used.
On laravel 8 everything worked as expected - because we laravel didn't update buildStack when resolving dependencies for method calls, and starting from 9 it is happening here - https://github.com/laravel/framework/blob/11.x/src/Illuminate/Container/Container.php#L685
Steps To Reproduce
Service provider:
TestClass:
Test:
TestCommand:
Set
LOG_DEPRECATIONS_CHANNEL=single
Run
php artisan test:deprecation
- you will get an exception thatchannel
method does not existThe text was updated successfully, but these errors were encountered: