CodeIgniter Forums
Call to undefined function CodeIgniter\Config\putenv() - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Call to undefined function CodeIgniter\Config\putenv() (/showthread.php?tid=82406)



Call to undefined function CodeIgniter\Config\putenv() - RizonBarns - 07-07-2022

In production environment. I got this issue. The hosting provider had blocked the putenv() function for security reason.

Quote:Fatal error: Uncaught Error: Call to undefined function CodeIgniter\Config\putenv() in /www/wwwroot/idp/printerp_api/vendor/codeigniter4/framework/system/Config/DotEnv.php:92 Stack trace: #0 /www/wwwroot/idp/printerp_api/vendor/codeigniter4/framework/system/Config/DotEnv.php(77): CodeIgniter\Config\DotEnv->setVariable() #1 /www/wwwroot/idp/printerp_api/vendor/codeigniter4/framework/system/Config/DotEnv.php(43): CodeIgniter\Config\DotEnv->parse() #2 /www/wwwroot/idp/printerp_api/public/index.php(30): CodeIgniter\Config\DotEnv->load() #3 {main} thrown in /www/wwwroot/idp/printerp_api/vendor/codeigniter4/framework/system/Config/DotEnv.php on line 92

When i'm looking for the source of DotEnv.php, it didn't check the function exists or not.

PHP Code:
protected function setVariable(string $namestring $value '')
{
    if (! getenv($nametrue)) {
        putenv("{$name}={$value}"); // <== Here's the error occurred.
    }

    if (empty($_ENV[$name])) {
        $_ENV[$name] = $value;
    }

    if (empty($_SERVER[$name])) {
        $_SERVER[$name] = $value;
    }


So i have to remark the 92nd line of codes.


RE: Call to undefined function CodeIgniter\Config\putenv() - Rarach - 04-05-2023

Please, I'm begging you, begging you. How did you solved it?


RE: Call to undefined function CodeIgniter\Config\putenv() - kenjis - 04-05-2023

Try to add this in app/Common.php:
PHP Code:
if (! function_exists('putenv')) {
    function putenv(string $assignment) {}