1

I need help with this error in the screenshot below

I am using PHP 7.2 and a 3rd party composer - "composer require vlucas/phpdotenv" v4.1.4.

I define the base path but there is an error in the screenshot

Error message

Below is the _env.php code that define my base path

<?php

    # define base path

    define('BASE_PATH', realpath(__DIR__.'/../../'));

    #require the 3rd party tool - composer autoload file

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

    $dotEnv = Dotenv\Dotenv::create(BASE_PATH); -----ERRO IN THIS PARENTHESIS


    $dotEnv->load();
?>

I changed the code to the one below but the error remain the same

<?php

    # define base path

    define('BASE_PATH', realpath(__DIR__.'/../../'));

    #require the 3rd party tool - composer autoload file

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

    $dotEnv = new Dotenv\Dotenv(BASE_PATH);


    $dotEnv->load();
?>
Nico Haase
  • 11,420
  • 35
  • 43
  • 69
Emmanuel Oga
  • 69
  • 2
  • 11

3 Answers3

0

Use this instead:

$dotenv = Dotenv\Dotenv::createUnsafeImmutable(BASE_PATH);

$dotenv -> load();

0

I hope this will help you

My Directory Structure is like 
- Vendor
- index.php
- .env

index.php

    $envPath = './';
    
    $dotenv = Dotenv\Dotenv::createImmutable(__DIR__ .$envPath);
    $dotenv->load();
    print_r($_ENV);
-1

Dotenv::create method expects two parameters but you passed only one, for the documentation see here https://github.com/vlucas/phpdotenv

$dotenv = Dotenv\Dotenv::create($repository, __DIR__);
Mahabubul Hasan
  • 1,396
  • 13
  • 20