diff --git a/src/DotEnv.php b/src/DotEnv.php index aacd4b5..ab92319 100644 --- a/src/DotEnv.php +++ b/src/DotEnv.php @@ -121,15 +121,17 @@ protected function parse(array $lines) : array */ protected function value($value) { - if ($value === 'null') { - $value = null; - } elseif ($value === 'true') { - $value = true; - } elseif ($value === 'false') { - $value = false; - } else { - $value = str_replace('\n', "\n", $value); + if ($value === 'null' || $value === '') { + return null; } + if ($value === 'true' || $value === 'false') { + return $value === 'true' ? true : false; + } + if (is_numeric($value)) { + return is_int($value) ? intval($value) : floatval($value); + } + + $value = str_replace('\n', "\n", $value); return is_string($value) ? trim($value) : $value; } diff --git a/tests/.env.test b/tests/.env.test index c85ecca..4469dc0 100644 --- a/tests/.env.test +++ b/tests/.env.test @@ -18,5 +18,5 @@ jumps over the lazy fox' BAD_ENV = omg NUMBER=123 -FLOAT=123.4 +FLOAT=456.78 export SOMEVAR="result" \ No newline at end of file diff --git a/tests/DotEnvTest.php b/tests/DotEnvTest.php index 2c3bda4..5b0d95f 100644 --- a/tests/DotEnvTest.php +++ b/tests/DotEnvTest.php @@ -39,8 +39,8 @@ public function testLoadAndParsing() $dotenv->load(__DIR__, '.env.test'); // TestApp $results = $dotenv->getEnv(); - - $this->assertEquals('3a4e41e63f65b228e2927d6045c09577', md5(json_encode($results))); + + $this->assertEquals('a8aa5046852048e0655d987528719c54', md5(json_encode($results))); } public function testLoadExecption()