Fatal error: Call to a member function on a non-object

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I am working on a set of PHP framework so to speak, designed to create module based community & content management based scripts. I just started updating the authentication handlers, which are all PHP 4 classes, and reworking a long list of changes. The new version i am coding is near completely incompatible with the old version hence it is extremely hard for me to compare the new to the old for these errors.

The problem here is PHP is returning the error "Fatal error: Call to a member function on a non-object in /home/thenubs/public_html/nauth7b/classes/Auth.class.php on line 24"

Out of this I have two questions which are
First, if a fatal error is occurring on line 24, why is it executing line 24 successfully and returning data? And second, if there?s a fatal error on line 24, why is line 25 still processed?

If anyone sees an alternative way to do what I am doing that might work better to solve the script errors then I am more than welcome to it as well seeing how my goal is just to get the script to run right. It seems like this might just be an error in PHP anyways, but I haven?t found anything on the net about similar occurrences yet.

The explanation and all of the code that you should need in order to see what?s going in is below.

The output of the entire page is:

SELECT userid, username, password FROM users WHERE username='XeRnOuS' Resource id #15 stdClass Object ( [userid] => 1 [username] => XeRnOuS [password] => $1$684gXdqL$MwtGhJGa7WkEbQoXe/474. ) 55

Fatal error: Call to a member function on a non-object in /home/thenubs/public_html/nauth7b/classes/Auth.class.php on line 24

Finally here is the code for the first part of the Auth class that i am working on.


<?php

class Auth
{
       var $loggedIN = false;
       var $userID = null;
       var $authSID;
       var $userIP;

       var $sql;
       var $err;
       var $perms;
       var $config;
       var $userperms = null;

       function Auth(&$sql, &$err, &$perms)
       {
//set realtive variables for the sql, err, and perms classes into the current class for easy access.
               $this->sql = &$sql;
               $this->err = &$err;
               $this->perms = &$perms;
               $this->config = &$GLOBALS['config'];

$userdat = $sql->fetch_object($sql->query("SELECT userid, username, password FROM users WHERE username='XeRnOuS'"));
               echo '<h1>';print_r($userdat);  echo '55</h1>';

               $this->authSID = session_id();
               $this->userIP = $_SERVER['REMOTE_ADDR'];


if(!is_object($this->sql)) echo '<h1>$sql IS NOT VALID OBJECT</h1>'; if(!method_exists($this->sql, 'query')) echo '<h1>QUERY IS NOT A VALID METHOD</h1>'; //destroy timed-out login sessions. Standard users will stay logged for 1 hour before session is destroyed $time = time() - 60 * 60; #60 minutes * 60 seconds per minute = 1 hour ago.

//if user is logged into the website, update it in $this->loggedIN for quick access for class //also change $this->userperms from guest permissions to $this->userID's specific permissions. if($_SESSION['loggedIN'] === true && !is_null($_SESSION['userID']))
               {
//check to see if user's session is still active in sql.auth_sessions if($this->Auth($_SESSION['userID'], session_id(), $_SESSION['userIP']))
                       {
                               $this->userID = $_SESSION['userID'];
$this->userperms = $this->perms->getUserPerms($this->userID);

//check to see if sql.auth_sessions.flogout is set, force user logout if is //otherwise update sql.auth_sessions.lastaccess to current unix time stamp

$userdat = $this->sql->fetch_object($this->sql->query("SELECT flogout FROM auth_sessions WHERE userID=\"$this->userID\" AND authSID=\"$this->authSID\" AND userIP=\"$this->userIP\""));
                               if($userdat->flogout === 1)
                               {
                                       $this->Logout();
                               }
                               else
                               {
$this->sql->query("UPDATE auth_sessions SET lastaccess=\"".time()."\" WHERE userID=\"$this->userID\" AND authSID=\"$this->authSID\" AND userIP=\"$this->userIP\"");
                               }
                       }
                       else
                       {
//users session has timed out, unset session information, for auth, set userperms to guest permissions
                               $_SESSION['loggedIN'] = false;
                               $_SESSION['userID'] = null;
                               $this->userperms = $perms->getGuestPerms();
                       }


               }
               else
               {
                       //set user permissions file to guest permissions
                       $this->userperms = $this->perms->getGuestPerms();
               }
               return true;
       }


As you can see i have three main classes, and the scripts use pointers to point to the original definitions of these classes to simplify the access and save memory. $sql is a class that has all the php4 compatible mysql functions defined in it. The syntax is the same as normal mysql function calls, but i added additional processing and error handling on the side of them, and changed a few of the default values. This is mostly used for development purposes so i can debug everything quickly.

the $sql->query function has the following code in it:

     function query($res, $fatal=0)
     {
             echo '<h3>'.$res;
             $res = mysql_query($res, $this->db_link);
             if(!$res)
             {
$this->addError('SQL->query', 'SQL Error', 'Failed to execute the MySQL Query.', $fatal);
             }
             else
             {
                     echo '        '.$res.'</h3>';
                     return $res;
             }
             return false;
     }

Now when we look at line 24 and 25 of the Auth class i have there, we find these two lines specifically

$userdat = $sql->fetch_object($sql->query("SELECT userid, username, password FROM users WHERE username='XeRnOuS'"));
               echo '<h1>';print_r($userdat);  echo '55</h1>';

with that in mind its easy to see how the data is generated for the most part. it calls sql->query which outputs the SQL query and the resource id for that sql query, defines the object, then outputs what the objects values are with the letter 55 in big h1 letters.

It's calling both of those SQL functions properly otherwise it wouldn?t be displaying any data. Yet for some reason it is saying that there?s a Fatal Error on line 24, and I?m calling a member function on a non-object.

Hence once more my questions are:
First, if a fatal error is occurring on line 24, why is it executing line 24 successfully and returning data?
Second, if there?s a fatal error on line 24, why is line 25 still processed?

I've been working on this for the better part of four hours and i would appreciate any help you guys can give me.

Thanks
- XeRnOuS

_________________________________________________________________
WIN up to $10,000 in cash or prizes ? enter the Microsoft Office Live Sweepstakes http://clk..atdmt.com/MRT/go/aub0050001581mrt/direct/01/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux