@@ -150,6 +150,9 @@ Configuration Classes and Environment Variables
150
150
When you instantiate a configuration class, any *namespaced * environment variables
151
151
are considered for merging into the configuration object's properties.
152
152
153
+ .. important :: You cannot add a new property by setting environment variables,
154
+ nor change a scalar value to an array. See :ref: `env-var-replacements-for-data `.
155
+
153
156
If the prefix of a namespaced variable exactly matches the namespace of the configuration
154
157
class, then the trailing part of the setting (after the dot) is treated as a configuration
155
158
property. If it matches an existing configuration property, the environment variable's
@@ -180,20 +183,26 @@ Since v4.1.5, you can also write with underscores::
180
183
181
184
.. note :: When using the *short prefix* the property names must still exactly match the class defined name.
182
185
186
+ .. _env-var-replacements-for-data :
187
+
183
188
Environment Variables as Replacements for Data
184
189
==============================================
185
190
186
191
It is very important to always remember that environment variables contained in your **.env ** are
187
- **only replacements for existing data **. This means that you cannot expect to fill your **.env ** with all
188
- the replacements for your configurations but have nothing to receive these replacements in the
189
- related configuration file(s).
192
+ **only replacements for existing data **.
193
+
194
+ Simply put, you can change only the property value that exists in the Config class
195
+ by setting it in your **.env **.
196
+
197
+ You cannot add a property that is not defined in the Config class, nor can you
198
+ change it to an array if the value of the defined property is a scalar.
190
199
191
- The **.env ** only serves to fill or replace the values in your configuration files. That said, your
192
- configuration files should have a container or receiving property for those. Adding so many variables in
193
- your **.env ** with nothing to contain them in the receiving end is useless.
200
+ For example, you cannot just put ``app.myNewConfig = foo `` in your **.env ** and
201
+ expect your ``Config\App `` to magically have that property and value at run time.
194
202
195
- Simply put, you cannot just put ``app.myNewConfig = foo `` in your **.env ** and expect your ``Config\App ``
196
- to magically have that property and value at run time.
203
+ When you have the property ``$default = ['encrypt' => false] `` in your
204
+ ``Config\Database ``, you cannot change the ``encrypt `` value to an array even if
205
+ you put ``database.default.encrypt.ssl_verify = true `` in your **.env **.
197
206
198
207
Treating Environment Variables as Arrays
199
208
========================================
0 commit comments