10000 Environment variable typecast processors return null when used in conjunction with default: · Issue #50415 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Environment variable typecast processors return null when used in conjunction with default: #50415
Closed
@melkamar

Description

@melkamar

Symfony version(s) affected

5.4.22

Description

When typecast env-var processors (e.g. bool:) are used together with default, the expression may evaluate to null.

When OPTIONAL_ENV_VAR is undefined in the following example, the default: processor will assign null to the result, and the bool: processor will pass it through, even though the documentation states the return type is bool. This is a problem when the value is passed as an non-nullable argument to a strictly-typed class.

\EnvironmentService:
  arguments:
    $boolFlag: '%env(bool:default::OPTIONAL_ENV_VAR)%'

This is not indented and the processor should be strictly non-nullable, as per the initial discussion here symfony/symfony-docs#18283 .

How to reproduce

Pass the following as an argument to a Symfony service. Do not set the value of OPTIONAL_ENV_VAR.

final class EnvironmentService
{
    public function __construct(
        private bool $boolFlag,
    ) {}
}
# services.yaml
\EnvironmentService:
  arguments:
    $boolFlag: '%env(bool:default::OPTIONAL_ENV_VAR)%'

Symfony container build will fail due to null being passed as the $boolFlag which has to be a bool.

Possible Solution

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0