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.
if you define a constant instead of a variable, this problem should be solved,
definition
old:
$ROOT_PATH = 'C:/Users/me/Documents/app-qas.com/site';
new:
define('ROOT_PATH', 'C:/Users/me/Documents/app-qas.com/site');
usage
old:
$root=$ROOT_PATH;
new:
$root = ROOT_PATH;