Skip to content

Conversation

cosmastech
Copy link
Contributor

@cosmastech cosmastech commented Sep 30, 2025

relying on the result of require_once doesn't work if multiple packages are being uninstalled 😓 require_once returns true the second time it's called (TIL).

Instead, we leverage Container::getInstance() and live happily ever after. 🤞

See discussion: #57220

Thanks to @htulibacki for reporting this and helping test.

Co-authored-by: htulibacki <[email protected]>
@taylorotwell taylorotwell merged commit 0d1344c into laravel:12.x Sep 30, 2025
63 checks passed

/** @var Application $app */
$app = require_once $bootstrapFile;
require_once $bootstrapFile;
Copy link
Contributor

@AhmedAlaa4611 AhmedAlaa4611 Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we still need require_once $bootstrapFile; and we have Container::getInstance()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

require_once $bootstrapFile fetches the user-defined Application builder. This will resolve the Container's instance during its setup.

The first time you call require_once $bootstrapFile, it does return an instance of Application. If you call it again during the life-cycle, it just returns true. (See the documentation for include_once where this behavior is mentioned).

The reason this is necessary is if you call composer remove laravel/telescope laravel/boost, this does not tear down and reboot the php interpreter for each package being removed. So for the first package removed, ComposerScripts::prePackageUninstall() is called, where require_once DOES return the application, but for the second package require_once just returns true.

Thus, this change:

  • ensures we have built the application according to project's application builder (bootstrap/app.php)
  • accesses the Application via the Container facade
  • ensures if we are removing multiple packages, it still works

Let me know if that makes sense or if you have any other questions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! That makes sense now. Other small question; do you think we should document the work done in #57144 and laravel/telescope#1641 in the package documentation, so developers can use this feature in their own packages when they need to register a service provider in the bootstrap/providers.php file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants