jgp4 Posted November 22, 2006 Share Posted November 22, 2006 Hi. I'm having trouble dealing with scope in one of my apps.I've written a class to handle dealing with the database, but the username, password and host data are in another file, so what I did, in index.php is include both files:include('includes/config.php');include('includes/classes/DBAdmin.php');and in the constructor for DBAdmin I try to access variables in config.php but it doesn't work. I put global $username; etc. in config.php, but the DBAdmin object still can't see them.Can an object only 'see' variables if they are inside its class?This leads to my second problem:I changed the constructor to include config.php directly, to get around the scope problem but I get an inclusion error.config.php is one level up from the class file and so I use include(../config.php);Is the path to the included file wrong, due to the fact that DBAdmin is included in index.php? Should I try include(includes/config.php instead);Thanks in advance Link to comment https://forums.phpfreaks.com/topic/28129-oo-php4-and-scope-problem/ Share on other sites More sharing options...
jgp4 Posted November 22, 2006 Author Share Posted November 22, 2006 just tried something newif I put a copy of config.php in the classes folder, and put include('config.php'); it works.So i assume that although the DBAdmin code is included into index.php and instantiated from it, when accessing the filesystem, it does so relative to DBAdmins.php's location rather than index.php's.Does that make sense? Link to comment https://forums.phpfreaks.com/topic/28129-oo-php4-and-scope-problem/#findComment-128653 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.