php – Use of undefined constant issue
Question
I have the following warning notice from my functions.php file:
Warning: Use of undefined constant ENVIRONMENT - assumed 'ENVIRONMENT' (this will throw an Error in a future version of PHP)
This is the code in my functions.php:
$dist_dir = get_theme_root_uri() . "/" . wp_get_theme() . "/dist";
/* environement */
// Set your environment/url pairs
$environments = array(
'local' => 'local.mysite.com',
'staging' => 'staging.mysite.com',
'production' => 'mysite.com'
);
// Get the hostname
$http_host = $_SERVER['HTTP_HOST'];
// Loop through $environments to see if there’s a match
foreach ($environments as $environment => $hostname) {
//echo $hostname . " www";
if (stripos($http_host, $hostname) !== false) {
define('ENVIRONMENT', $environment);
break;
}
}
if (ENVIRONMENT == 'local') {
define('ASSETSDIR', get_template_directory_uri() . '/assets');
} else {
define('ASSETSDIR', $dist_dir . '/assets');
}
The line in relation with the notice is this one:
if (ENVIRONMENT == 'local') {
I’m not sure to understand why there is this warning notice and how to solve it.
Thank you.
0
4 weeks
2023-01-02T11:22:06-05:00
2023-01-02T11:22:06-05:00 0 Answers
0 views
0
Leave an answer