-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Description
Description
We had an interesting issue today where we deployed the following code:
final class ServiceName
{
public function __construct(
#[Autowire(env: 'SANDBOX')]
public bool $sandbox,
) {}
}
And set the following in our .env
:
SANDBOX=false
The $sandbox
property in ServiceName
was set to true
.
It took us a while to understand what went wrong here. Because false
is seen as true-ish, it became true
.
We missed the bool
environment processor. Changing it to #[Autowire(env: 'bool:SANDBOX')]
solved it. So it was just a mistake on our end.
But that lead me to wonder: why can't Symfony warn me about this? Given that I use Autowire, it already knows that I'm targeting a boolean property. It would be great if it would say something like:
Warning: You should use the `bool` environment processor for `$sandbox` in `ServiceName`.
If you think this is a valid idea, what would be the best location to implement this check?
Somewhere around here?
symfony/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php
Lines 309 to 310 in ba614ef
foreach ($attributes as $attribute) { | |
$attribute = $attribute->newInstance(); |
Example
No response