Menu

Call to a member function on a non-object

Help
2001-11-19
2002-03-15
  • Angel Hernandez

    Angel Hernandez - 2001-11-19

    Hello,

    I've just tried installing phplib 7.2d with 4.0.3pl1 and Im getting the following error on defauth.php3 and showoff.php3:

    "Call to a member function on a non-object in /home/firemindz/firemindz.com/htdocs/php/page.inc on line 47"

    I *feel* as though I have everything setup right, since I can verify that sessions are being added to the DB, but maybe I've overlooked a setup step...

    Any ideas as to what's causing the "Call to a member function on a non-object " error?

    Thanks,
    Angel Hernandez

     
    • Anonymous

      Anonymous - 2001-11-20

      I am running phpslash with phplib and I get this all the time at the bottom of one of my pages:

      Fatal error: Call to a member function on a non-object in /usr/local/apache/php/php/page.inc on line 68

      Seems very similar to yours, but I don't know why I get it...

       
      • Anonymous

        Anonymous - 2002-03-15

        The problem here is that you try to call a method through a variable which is thought to be an instance of a certain class... But tough luck, this given variable is NOT what you think it is (e.g. it's not such an instance).

        Why in the case of phplib/page.inc?

        Look at the code fragment from page.inc
        (lines 67 - 69)
        ------------------
            if (isset($user)) {
              $user->freeze();
            }
        ------------------

        The condition is true because there is an existing variable $user. But the assumption that this is an instance of the expected class will be wrong, if a different variable with the name $user existed in the global scope before the class-instance was created.

        Code fragment from page.inc (lines 41 - 46)
        ------------------
              if (isset($feature["user"])) {
                global $user;
               
                if (!isset($user)) {
                  $user = new $feature["user"];
                }
        ------------------

        If the variable $user already exists, the instance will not be created and therefore there will be no memberfunction to be called...

        Solution:
        ---------
        What you have to look for in your own code is, that no global variable $user exists outside the userhandling of phplib! Search in all corners ;-)

        In my case $user was part of an old cookie on the clientside(1.5 years old!) coming from an old test-script... [DBG-Debugger helped a lot to find that one! Thanks Dimitri]. The cookie content was mapped into the global space and collided with phplib.

        This same scenario may arise for other scripts/vars too if one is not very strict in all assumptions about the global variables!

        Hope this helps to flush all those nasty messages away from the bottom lines of many sites.

         

Log in to post a comment.