Giter Site home page Giter Site logo

Unable to nest variables about phpdotenv HOT 9 CLOSED

CMDann avatar CMDann commented on May 2, 2024
Unable to nest variables

from phpdotenv.

Comments (9)

gmcgibbon avatar gmcgibbon commented on May 2, 2024

This has been fixed. We changed DB_DATABASE="BUILD_${DRONE_BUILD_NUMBER}" to DB_DATABASE="BUILD_{$DRONE_BUILD_NUMBER}".

Turns out ${...} is used for phpdotenv variables while {$...} is used for environment variables. You might want to clarify this in the documentation.

from phpdotenv.

vlucas avatar vlucas commented on May 2, 2024

phpdotenv follows the correct bash/shell syntax, which is ${...} for variable expansion and string interpolation. I just tried it in my shell:

$> export DRONE_BUILD_NUMBER=42
$> export DB_DATABASE="BUILD_${DRONE_BUILD_NUMBER}"
$> echo $DB_DATABASE                                                                                            ]
$> BUILD_42

You can also test it with:

source .env && echo $DB_DATABASE

from phpdotenv.

CMDann avatar CMDann commented on May 2, 2024

👍

from phpdotenv.

VanTanev avatar VanTanev commented on May 2, 2024

phpdotenv does not properly inline env variables in laravel 5.1

$ printenv | grep MYSQL_USER
MYSQL_USER=root

$ cat .env | grep DB_USERNAME
DB_USERNAME="${MYSQL_USER}"

$ php artisan migrate --force
SQLSTATE[HY000] [1045] Access denied for user '${MYSQL_USER}'@'localhost' (using password: YES)

$ source .env && echo $DB_USERNAME
root

Switching to DB_USERNAME="{$MYSQL_USER}" inside .env fixes the issue.

I don't know if this behavior has been changed since laravel 5.1, but it would definitely be good to mention it somewhere visible. Or, since the {$VAR} version seems to always work, maybe use that example in the documentation?

from phpdotenv.

GrahamCampbell avatar GrahamCampbell commented on May 2, 2024

Laravel 5.1 uses an old version of this package.

from phpdotenv.

GrahamCampbell avatar GrahamCampbell commented on May 2, 2024

https://github.com/vlucas/phpdotenv/tree/1.1

from phpdotenv.

VanTanev avatar VanTanev commented on May 2, 2024

But since Laravel's docs do not specify inline semantics, and people will look to this documentation for guidance, we're left with a very confusing error. I can try and open a PR to fix the Laravel docs, but probably not the only one who would look to your docs first.

Do you think mentioning the old syntax in the main README would be useful? Something along the lines of:

"For old versions of dotenv, use {$VAR} instead of ${VAR}"

from phpdotenv.

GrahamCampbell avatar GrahamCampbell commented on May 2, 2024

I'd say that I'd expect people to look at the readme for the correct version?

from phpdotenv.

VanTanev avatar VanTanev commented on May 2, 2024

Unfortunately, it's not that easy to know what the correct version is when it's vendored like this. Also, 5.1 is the LTS release of Laravel, so it's expected to stick around for a good while still (2 years active dev, 3 years security fixes, starting July 19, 2016).

The docs (https://laravel.com/docs/5.1#environment-configuration) also simply link to the latest version of DotEnv (instead of to ~1.0) adding to the confusion.

from phpdotenv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.