I created a config file that has a variable I want to use as a constant.
<?php
$ROOT_PATH = 'C:/Users/me/Documents/app-qas.com/site';
?>
On a CLASS page where I want to use the variable I added the following before instantiating the CLASS:
include_once("config.php");
$root=$ROOT_PATH;
I made the appropriate scoping changes to the functions in my class as follows: global $root; include_once($root."/Library/API/database.inc.php");
When I run my app, it DOES perform all of the data connections it is designed to do, BUT it STILL returns the following errors:
Warning: include_once(config.php): failed to open stream: No such file or directory in C:/Users/me/Documents/app-qas.com/site'\class\Posting.class.php on line 5
Warning: include_once(): Failed opening 'config.php' for inclusion (include_path='.;C:\php\pear') in C:/Users/me/Documents/app-qas.com/site'\class\Posting.class.php on line 5
Notice: Undefined variable: ROOT_PATH in C:/Users/me/Documents/app-qas.com/site'\class\Posting.class.php on line 6
Warning: include_once(/Library/API/database.inc.php): failed to open stream: No such file or directory in C:/Users/me/Documents/app-qas.com/site'\class\Posting.class.php on line 112
Warning: include_once(): Failed opening '/Library/API/database.inc.php' for inclusion (include_path='.;C:\php\pear') in C:/Users/me/Documents/app-qas.com/site'\class\Posting.class.php on line 112
Warning: include_once(/Library/API/database.inc.php): failed to open stream: No such file or directory in C:/Users/me/Documents/app-qas.com/site'\class\Posting.class.php on line 112
Warning: include_once(): Failed opening '/Library/API/database.inc.php' for inclusion (include_path='.;C:\php\pear') in C:/Users/me/Documents/app-qas.com/site'\class\Posting.class.php on line 112
If I comment out the include and hard code the $root it runs like before BUT it DOES NOT throw any errors:
#include_once("joblaunch.php");
#$root=$ROOT_PATH;
$root='C:/Users/me/Documents/app-qas.com/site';
I don't understand why it runs and throws errors when getting the variable from the config.php but runs and doesn't throw an error when hard coding the path.
define('ROOT_PATH', 'C:/Users/me/Documents/app-qas.com/site');and useROOT_PATH. Then you won't have any scoping problems.global $rootinside the functions that use it. Not in the global scope.database.inc.phpfile, then theglobal $roothas to go inside those functions. Not before you include the file.config.phpfile. The first error says it didn't find it. That's why it's not recognizing your config variable. Are you sureconfig.phpis in the same directory?