Why am I getting two different values for the environment variable PHPRC?

I've installed PHP 7.2.12 using the latest version of XAMPP.

I ran the code phpinfo(); and saw the output in the browser window.

In the output, under the heading Apache Environment I saw an environment variable named PHPRC which has a value \xampp\php

Then I created a file named demo.php and wrote below code in it and run the same code file and see the output in my web browser.

<?php
   var_dump($_ENV['PHPRC']);
?>

I saw the below output in my browser window :

Notice: Undefined index: PHPRC in C:\xampp\htdocs\demo.php on line 2
NULL 

Why so?

Why am I getting different and unexpected output when I tried to see the value of the environment variable PHPRC using superglobal array $_ENV['PHPRC']?

728x90

1 Answers Why am I getting two different values for the environment variable PHPRC?

As the header "Apache Environment" tells you, this is set by the web server, not the OS, so won't be available within $_ENV. Instead try using the apache_getenv() function.

echo apache_getenv("PHPRC");

4 months ago