New to Object-Oriented: Importing Variables(?)
Posted: Mon Apr 02, 2007 9:46 am
Hi gang,
I'm trying to give myself a quick introduction to Object-Oriented PHP. I'd always assumed you could call variables from inside classes without any problems...but it seems I'm wrong. Here's the problem.
I call (via require_once) my db_login.php file, and I also call (via require_once) connectionclass.php.
In connectionclass.php, I'm trying to access a variable from db_login.php ($db_username to be precise)...and it just won't recognise anything inside the class.
Echoing $db_username returns the correct variable if I echo it before the class is declared, but if I try to echo it from within the constructor function, it returns nothing. var_dump returns "NULL".
Apologies for what I suspect is quite a newbie-ish question, but if anyone can help out I'd be really appreciative.
Cheers,
- Dusty Puppet
I'm trying to give myself a quick introduction to Object-Oriented PHP. I'd always assumed you could call variables from inside classes without any problems...but it seems I'm wrong. Here's the problem.
I call (via require_once) my db_login.php file, and I also call (via require_once) connectionclass.php.
In connectionclass.php, I'm trying to access a variable from db_login.php ($db_username to be precise)...and it just won't recognise anything inside the class.
Echoing $db_username returns the correct variable if I echo it before the class is declared, but if I try to echo it from within the constructor function, it returns nothing. var_dump returns "NULL".
Apologies for what I suspect is quite a newbie-ish question, but if anyone can help out I'd be really appreciative.
Cheers,
- Dusty Puppet