[7.x] Throw a TypeError if concrete is not a string or closure#33539
Conversation
GrahamCampbell
left a comment
There was a problem hiding this comment.
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 🤝 |
| // 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.
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
concreteparameter passed tobindis not aClosure, then it is a string. Let's fail loudly if that is not the case.Problem surfaced here: facade/ignition#291