Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Env variable processor return empty string when used with default. #57442

Copy link
Copy link
Open
@Wiktor6

Description

@Wiktor6
Issue body actions

Symfony version(s) affected

6.4.8

Description

I'm updating my app from symfony v6.1.12 to v6.4.8 and behavior of env processor changed.

Before update env %env(string:default::ENV_NAME)% return null, but now it return empty string.

I found some PRs and issues, but there was fix to fix to fix, and I'm little bit confused what is the right way.

  1. [DependencyInjection] Fix casting scalar env vars from null #50517

  2. [DependencyInjection] Fix autocasting null env values to empty string #50837

  3. [DependencyInjection] Fix autocasting null env values to empty string with container.env_var_processors_locator #51198

  4. Environment variable typecast processors return null when used in conjunction with default: #50415

  5. Null environment variable cast to empty string #50815

In documentation there is "When the fallback parameter is omitted (e.g. env(default::API_KEY)), then the returned value is null.". I think 3rd PR says that null value shouldn't be casted to empty string.

Also, I modified my env to default::ENV_NAME and i have the same problem as described here

Invalid type for path "infrastructure_tools.healthChecks.baseAuthUser". Exp  
  ected one of "bool", "int", "float", "string", but got one of "bool", "int"  
  , "float", "string", "array". 

How to reproduce

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

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

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.