A value may reference another variable with ${NAME}. References are resolved
when you read the value with get(), not when the file is loaded.
SITE_URL = http://lvh.me
PAGE_URL = ${SITE_URL}/pageDotENV::get('PAGE_URL'); // "http://lvh.me/page"Any number of references may appear in a single value:
HOST = localhost
PORT = 8080
ADDR = ${HOST}:${PORT}DotENV::get('ADDR'); // "localhost:8080"A referenced value may itself contain references; they are resolved recursively:
A = root
B = ${A}/b
C = ${B}/cDotENV::get('C'); // "root/b/c"${NAME} is resolved with the same lookup that get() uses
($_ENV → $_SERVER → getenv()), so a reference can point at a real
environment variable, not just another line in the same file.
A reference is replaced with the string cast of the referenced value,
then the whole surrounding value is coerced as usual. So referencing a
coerced type behaves like PHP's (string) cast:
NAME value |
${NAME} inserts |
WRAP=${NAME} becomes |
|---|---|---|
"text" |
text |
"text" |
13 |
13 |
13 (int) |
true |
1 |
1 (int) |
false |
(empty) | "" |
null |
(empty) | "" |
A non-scalar referenced value (an array or object loaded from a .env.php
file) inserts an empty string.
A reference to an undefined name resolves to an empty string:
VALUE = ${DOES_NOT_EXIST}suffixDotENV::get('VALUE'); // "suffix"A reference back to a name that is still being resolved (a self-reference or a cycle) is replaced with an empty string instead of recursing forever. Any literal text around the reference is kept:
A = ${A}
B = ${C}
C = ${B}
D = ${D}-tailDotENV::get('A'); // ""
DotENV::get('B'); // ""
DotENV::get('C'); // ""
DotENV::get('D'); // "-tail" (the cyclic ${D} is dropped, "-tail" remains)