Skip to content

Commit bdf9efc

Browse files
dsminknicolas-grekas
authored andcommitted
Env var maps to undefined constant.
When I try to use a constant as an environment variable, as described in the blog item, I run into the following problem. Env var "SOME_CONST" maps to undefined constant "App\\Util\\SomeClass::SOME_CONST". The proposed solution works for me, however, I'm not sure if this is the best and conform Symfony standards. Blog: https://symfony.com/blog/new-in-symfony-3-4-advanced-environment-variables
1 parent a41874f commit bdf9efc

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/Symfony/Component/DependencyInjection/EnvVarProcessor.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,13 @@ public function getEnv($prefix, $name, \Closure $getEnv)
110110
}
111111

112112
if ('const' === $prefix) {
113+
$env = \str_replace("\\\\","\\", $env);
114+
113115
if (!defined($env)) {
114116
throw new RuntimeException(sprintf('Env var "%s" maps to undefined constant "%s".', $name, $env));
115117
}
116118

117-
return constant($name);
119+
return constant($env);
118120
}
119121

120122
if ('base64' === $prefix) {

0 commit comments

Comments
 (0)