-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
[7.x] Throw a TypeError if concrete is not a string or closure #33539
[7.x] Throw a TypeError if concrete is not a string or closure #33539
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
phpdoc says null is allowed, but your PR doesn't allow it
I'm not sure how |
Would you like me to squash or do you squash when merging? |
Don't worry about that. Taylor can squash (or not) if he wants. :) |
Thanks for the feedback @GrahamCampbell , it's appreciated 🤝 |
@@ -234,6 +234,10 @@ public function bind($abstract, $concrete = null, $shared = false) | |||
// bound into this container to the abstract type and we will just wrap it | |||
// up inside its own Closure to give us more convenience when extending. | |||
if (! $concrete instanceof Closure) { | |||
if (! is_string($concrete)) { | |||
throw new \TypeError(self::class.'::bind(): Argument #2 ($concrete) must be of type Closure|string|null'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note for Taylor: This error message format is what PHP 8.0 does when there's a genuine union type.
We may just eventually use a real union type here. |
@taylorotwell the reason for this PR was to stop real bugs, not just to add a type for the sake of it. |
I have to agree with @GrahamCampbell here -- this issue took me several hours to realize. Even if we decide to use a real union type here in the future, I strongly believe it would be beneficial to add this validation now. |
Not sure what I need to do, but it seems that this PR has created all sorts of bind errors not sure how to resolve them for example when I run ` TypeError Illuminate\Container\Container::bind(): Argument #2 ($concrete) must be of type Closure|string|null at vendor/laravel/framework/src/Illuminate/Container/Container.php:238
11 artisan:37 |
This is because there's a mistake in your code, which is now being caught and showed to you. That was the exact purpose of this. PR. :) |
Can you show the whole stack trace? |
That is all the stack trace that I get, I do not know which migration has the issue since it is not highlighted |
If you run the command in verbose mode, more should show. |
I get the same output My environment is PHP 7.3.20 (cli) (built: Jul 9 2020 23:50:54) ( NTS ) |
|
You should use |
Tried that and Interesting I have these two dependencies "laravel/framework": "^7.0",
|
I don't think so. The issue will be in one of your service providers, or possibly one provided in the core. Please show us the stack trace, or this will never be fixed (we can only fix it if we know where it is). |
Maybe my composer.json may help
|
What's your actual version of facade / ignition? If you look at my original PR description, you'll see this was actually as a result of a bug in facade/ignition which I fixed in the latest release. Please try updating it. Otherwise we are just speculating without seeing a full stack trace. |
Thank you very much for your patience, I was only looking at the console for the error message, forgetting the logs I found that the pragmarx/health dependency was the one causing the closure issue. I will go ahead and open an issue there |
I was having the same issue and also have that package installed. Thank you! |
There is currently an assumption that if the
concrete
parameter passed tobind
is not aClosure
, then it is a string. Let's fail loudly if that is not the case.Problem surfaced here: facade/ignition#291