Jump to content

OO php4 and scope problem


jgp4

Recommended Posts

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

just tried something new

if 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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.