HappyFeet Posted January 26, 2012 Share Posted January 26, 2012 Evening, So I have three files. run.php // autoload the classes function __autoload($className) { include "class.".$className.".php"; } // setup the sessions handler $session = new Session($member); // setup the handler $handler = new Handler(part, template, $_GET); The handler takes the $_GET data and includes the templates header -> $_GET matching body file -> footer and returns it forming a page. However. When I go to call something from the Session class for example in the body file with... body.tpl.php <?=$Session->isLog();?> I get... Notice: Undefined variable: Session in .../body.tpl.php on line 12 Fatal error: Call to a member function isLog() on a non-object in .../body.tpl.php on line 12 It is my understanding that the class is ready for use, but isn't? I'd really appreciate any advice you can spare. Quote Link to comment https://forums.phpfreaks.com/topic/255847-calling-something-autoloaded/ Share on other sites More sharing options...
DavidAM Posted January 26, 2012 Share Posted January 26, 2012 $session (lowercase name) is not the same as $Session (uppercase name). Quote Link to comment https://forums.phpfreaks.com/topic/255847-calling-something-autoloaded/#findComment-1311518 Share on other sites More sharing options...
HappyFeet Posted January 26, 2012 Author Share Posted January 26, 2012 Yep. The file is: class.Session.php - which is why it's $Session. Case sensitive... either way, both give the same error. Quote Link to comment https://forums.phpfreaks.com/topic/255847-calling-something-autoloaded/#findComment-1311519 Share on other sites More sharing options...
DavidAM Posted January 26, 2012 Share Posted January 26, 2012 I've never used autoload, but the way I understand it, the code in your first block should fire it: // setup the sessions handler $session = new Session($member); and should autoload the Session class (in class.Session.php) creating an object which is stored in the variable $session (lower case name). You could just as easily call it $abc it should not matter. However, you are referring to it in the second code block as <?=$Session->isLog();?> using an uppercase name ($Session). The error message says Notice: Undefined variable: Session in .../body.tpl.php on line 12 which is saying that the variable $Session (uppercase name) does not exist. If you change that to be the lowercase name ($session), you should not get the same error message -- does it then tell you that $session (lowercase name) does not exist? We don't see enough of the code to know if there is a scope issue here. The object you created exists in whatever scope (Global or function or class) that it is instantiated in. So your reference to it must be in the same scope; otherwise, the variable does not exist (in scope). Have you tested to see if the object is, in fact, being instantiated? // setup the sessions handler $session = new Session($member); if (! is_object($session)) trigger_error('Session Object Not Instantiated', E_USER_ERROR); although, I would expect you to get an error at that point if it did not. Quote Link to comment https://forums.phpfreaks.com/topic/255847-calling-something-autoloaded/#findComment-1311524 Share on other sites More sharing options...
HappyFeet Posted January 26, 2012 Author Share Posted January 26, 2012 does it then tell you that $session (lowercase name) does not exist? In fact no, my apologies there! There is no error if you replace the upper case with a lower case 's', but there is nothing returned from the class. Have you tested to see if the object is, in fact, being instantiated? It is being initiated, there are no errors from what you posted. Currently the "class.Session.php" file is simply: class Session { public function __construct(){ // Nothing yet. } /** * Logged in? */ public function isLog(){ if(isset($_SESSION['memberID'])){ return "YES"; } else { return "NO"; } } } Quote Link to comment https://forums.phpfreaks.com/topic/255847-calling-something-autoloaded/#findComment-1311526 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.