Fatal error: Uncaught TypeError: Dotenv\Dotenv::__construct(): Argument #1 ($store) must be of type Dotenv\Store\StoreInterface, string given, called in C:\xampp\htdocs\PHPTheCompletePHPMVCourse_I\app\config_env.php on line 7 and defined in C:\xampp\htdocs\PHPTheCompletePHPMVCourse_I\vendor\vlucas\phpdotenv\src\Dotenv.php:60 Stack trace: #0 C:\xampp\htdocs\PHPTheCompletePHPMVCourse_I\app\config_env.php(7): Dotenv\Dotenv->__construct('C:\xampp\htdocs...') #1 C:\xampp\htdocs\PHPTheCompletePHPMVCourse_I\public\index.php(3): require_once('C:\xampp\htdocs...') #2 {main} thrown in C:\xampp\htdocs\PHPTheCompletePHPMVCourse_I\vendor\vlucas\phpdotenv\src\Dotenv.php on line 60
I am geting this error when trying to "echo" APP_NAME in ".env" file. I am using "vlucas/phpdotenv 5.5" and app works fine with "vlucas/phpdotenv 2.4"
index.php in C:\xampp\htdocs\PHPTheCompletePHPMVCourse_I\public
<?php
require_once __DIR__ . '/../app/config/_env.php';
$app_name = getenv('APP_NAME');
echo $app_name;
.env in C:\xampp\htdocs\PHPTheCompletePHPMVCourse_I
APP_URL=http://localhost/PHPTheCompletePHPMVCourse_I
APP_ENV=local
APP_NAME="ACME E-commerce Store"
#database
DB_DRIVER='mysql'
DB_HOST=localhost
DB_NAME=store
DB_USERNAME=store
DB_PASSWORD=secret
_env in C:\xampp\htdocs\PHPTheCompletePHPMVCourse_I\app\config
<?php
define('BASE_PATH', realpath(__DIR__.'/../../'));
require_once __DIR__.'/../../vendor/autoload.php';
$dotEnv = new Dotenv\Dotenv(BASE_PATH);
$dotEnv->load();
Dotenv.php in C:\xampp\htdocs\PHPTheCompletePHPMVCourse_I\vendor\vlucas\phpdotenv\src
line 60 -> public function __construct(
StoreInterface $store,
ParserInterface $parser,
LoaderInterface $loader,
RepositoryInterface $repository
) {
$this->store = $store;
$this->parser = $parser;
$this->loader = $loader;
$this->repository = $repository;
}
I tried following changes in _env in C:\xampp\htdocs\PHPTheCompletePHPMVCourse_I\app\config
$dotEnv = Dotenv\Dotenv::createImmutable(BASE_PATH);
$dotEnv->safeLoad();
got no errors but nothing comes up
source https://stackoverflow.com/questions/76195575/php-fatal-error-uncaught-typeerror-dotenv-dotenv-construct-argument-1
No comments:
Post a Comment