-
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
Application booted callbacks called twice #53589
Comments
A potential fix would be to update public function booted($callback)
{
if ($this->isBooted()) {
$callback($this);
} else {
$this->bootedCallbacks[] = $callback;
}
} I just don't have the time available to write tests and submit a PR right now. |
What's your actual use case for this? |
Do you require me to provide you with a detailed use-case in order for this bug to be fixed? Because I can do that, but I just don't see it as being a constructive use of one's time. In short, I discovered this issue while integrating packages maintained by separate developers, where both packages need to ensure that actions occur after application boot, and one of those packages also provides a mechanism for triggering callbacks after it has booted (although not actual package boot, but it's own concept of "booting" as it provides support for extensions/addons/plugins). Now the first package would either have to depend on the second always executing it's booted callbacks after application boot (which is risky and not guaranteed), or it could simply add it's own application booted callbacks that are added during the second packages booted callbacks. That being said, do please let me know if you require a detailed use-case. |
|
|
I think we could either: Option A: Swap lines 1105 and 1107 from the framework/src/Illuminate/Foundation/Application.php Lines 1090 to 1108 in eb625fa
IMO, the internal Option B: Change the framework/src/Illuminate/Foundation/Application.php Lines 1144 to 1151 in eb625fa
to: public function booted($callback)
{
if ($this->isBooted()) {
$callback($this);
} else {
$this->bootedCallbacks[] = $callback;
}
} This is more cumbersome, as the callbacks are no longer cached, but as I think both "fixes" could be considered. Unless we want to keep track of Currently, from my understanding, the For the record, I tested both options on a local fresh Laravel project, and both seem to resolve the issue. Unfortunately, I won't be able to work on a proper PR for the next few days. If someone wants to give it a shot, it would be great. |
Laravel Version
11.33.2
PHP Version
8.2.23
Database Driver & Version
SQLite
Description
Booted callbacks are being called twice when they are registered within another booted callback.
Steps To Reproduce
Create a fresh
laravel/laravel
project and add the following to theregister
method ofApp\Providers\AppServiceProvider
:Execute
php artisan about
and it will show the following:The text was updated successfully, but these errors were encountered: