Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`$` variable in .env not the same after loading through symfony-dotenv

Putting $ symbols in an environment variable in a .env file, the symfony/dotenv loader seems to mess something up.

.env

TEST=123123123!!!123123123$$LOST$$testtesttest~~~tiltiltiltil

test.php

<?php
require_once __DIR__ . '/vendor/autoload.php';

$dotenv = new \Symfony\Component\Dotenv\Dotenv();
$dotenv->load('.env');

print_r($_ENV);

Output:

[TEST] => 123123123!!!123123123$$~~~tiltiltiltil

Expected output:

[TEST] => 123123123!!!123123123$$LOST$$testtesttest~~~tiltiltiltil

My question is if this is a bug or me doing something wrong.

It does not matter whether I wrap the value in quotes.

If it's not me, I'd create an issue on GitHub.

like image 221
Daniel W. Avatar asked Sep 05 '25 02:09

Daniel W.


1 Answers

The $ sign has a special meaning so to insert a literal dollar you need to either quote it or escape it:

TEST='123123123!!!123123123$$LOST$$testtesttest~~~tiltiltiltil'
TEST=123123123!!!123123123\$\$LOST\$\$testtesttest~~~tiltiltiltil
like image 70
Álvaro González Avatar answered Sep 07 '25 09:09

Álvaro González