From f300e8444e159105a208ff92beec47a42b4af151 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Fri, 13 Jan 2023 18:46:30 +0100 Subject: [PATCH] [Configuration] Add $_ENV and $_SERVER example with .env --- configuration.rst | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/configuration.rst b/configuration.rst index f1f66be2fdf..5eb70fed1b6 100644 --- a/configuration.rst +++ b/configuration.rst @@ -58,7 +58,7 @@ Configuration Formats ~~~~~~~~~~~~~~~~~~~~~ Unlike other frameworks, Symfony doesn't impose a specific format on you to -configure your applications, but lets you choose between YAML, XML and PHP. +configure your applications, but lets you choose between YAML, XML and PHP. Throughout the Symfony documentation, all configuration examples will be shown in these three formats. @@ -653,6 +653,12 @@ This example shows how you could configure the database connection using an env ]); }; +Your env vars may also be accessed in your code thanks to PHP super +globals ``$_ENV`` and ``$_SERVER``. Both are equivalent:: + + $databaseUrl = $_ENV['DATABASE_URL']; // mysql://db_user:db_password@127.0.0.1:3306/db_name + $env = $_SERVER['APP_ENV']; // prod + .. versionadded:: 5.3 The ``env()`` configurator syntax was introduced in 5.3.