DEV Community

Discussion on: Build a Simple REST API in PHP

Collapse
 
skipperski profile image
marekszyperski

Salam Mohammad!

I have a problem:
PHP Fatal error: Uncaught TypeError: Dotenv\Dotenv::__construct(): Argument #1 ($store) must be of type Dotenv\Store\StoreInterface, string given, called in /Applications/XAMPP/xamppfiles/htdocs/api/start.php on line 7 and defined in /Applications/XAMPP/xamppfiles/htdocs/api/vendor/vlucas/phpdotenv/src/Dotenv.php:60
Stack trace:

0 /Applications/XAMPP/xamppfiles/htdocs/api/start.php(7): Dotenv\Dotenv->__construct('/Applications/X...')

1 {main}

thrown in /Applications/XAMPP/xamppfiles/htdocs/api/vendor/vlucas/phpdotenv/src/Dotenv.php on line 60

10.4.18-MariaDB, PHP 8

Collapse
 
skipperski profile image
marekszyperski

Ok, I use new phpdotenv and many change...

Don't use getenv only $_ENV example $host = $_ENV['DB_HOST'];

and

$dotenv = Dotenv\Dotenv::createImmutable(DIR);
$dotenv->load();
=> "createImmutable"

Collapse
 
shahbaz17 profile image
Mohammad Shahbaz Alam

Thanks for bringing this into my attention.

New version is really good. Also, I have update the guide to reflect the same.

Collapse
 
shahbaz17 profile image
Mohammad Shahbaz Alam

Are you still getting the same error @skipperski ? or have you solved it using the new approach?