0

I use environment variables to configure my app. Thus, I try to set the email configuration from my .env file.

<?php

namespace Config;

use CodeIgniter\Config\BaseConfig;

class Email extends BaseConfig
{
    /**
     * @var string
     */
    public $fromEmail = $_ENV['FROMMAIL'];

    ...
}

I'm getting the error:

Fatal error: Constant expression contains invalid operations

How can I assign a ENV variable to a class variable?

What I tried as well is:

<?php

namespace Config;

use CodeIgniter\Config\BaseConfig;

class Email extends BaseConfig
{
    /**
     * @var string
     */
    public $fromEmail = "test";

    ...

    function __construct()
    {
       $this->fromMail = $_ENV['FROMMAIL'];
    }
}

where $_ENV['FROMMAIL'] = "test@mail.com";. But this is using the value "test" instead of my environment variable.

Nick Rick
  • 75
  • 6

0 Answers0