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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • André Somers

    #1

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

    Hi,

    I'm having a problem that I have a hard time understanding. I am getting a
    "Fatal error: Call to a member function on a non-object" on a constructor
    of a class, that looks like this (simplified):

    class phpBB_Template {
    var $classname = "Template";

    // Root template directory.
    var $root = "";

    /**
    * Constructor. Simply sets the root dir.
    *
    */
    function phpBB_Template( $root = ".")
    { /* Error is reported on this line */
    $this->root = $root;
    }
    }

    The line where the error is reported only contains the function's opening
    accolade. As far as I understand, this error should only occur if I try to
    access a function on a variable that is not an object, but the only
    variable I am accessing, is $this, and that one is by definition an object,
    right?

    Please help!

    André
  • André Somers

    #2
    Re: Fatal error: Call to a member function on a non-object in constructor?

    André Somers wrote:
    [color=blue]
    > I'm having a problem that I have a hard time understanding. I am getting a
    > "Fatal error: Call to a member function on a non-object" on a constructor
    > of a class, that looks like this (simplified):[/color]
    Please ignore the above, I just wasn't looking hard enough. The problem was
    in a different file with a very similar name... Silly me...

    André

    Comment

    • Chris Widmer

      #3
      Re: Fatal error: Call to a member function on a non-object in constructor?

      Hi,

      your code works fine on my computer. have you tried this:

      class phpBB_Template {
      var $classname = "Template";

      // Root template directory.
      var $root; //<----change here!



      /**
      * Constructor. Simply sets the root dir.
      *
      */
      function phpBB_Template( $root = ".")
      { /* Error is reported on this line */
      $this->root = $root;
      }
      }

      i think in php4 you're not supposed to declare non-constand vars like
      that: var $root = "blah".




      André Somers wrote:
      [color=blue]
      > Hi,
      >
      > I'm having a problem that I have a hard time understanding. I am getting a
      > "Fatal error: Call to a member function on a non-object" on a constructor
      > of a class, that looks like this (simplified):
      >
      > class phpBB_Template {
      > var $classname = "Template";
      >
      > // Root template directory.
      > var $root = "";
      >
      > /**
      > * Constructor. Simply sets the root dir.
      > *
      > */
      > function phpBB_Template( $root = ".")
      > { /* Error is reported on this line */
      > $this->root = $root;
      > }
      > }
      >
      > The line where the error is reported only contains the function's opening
      > accolade. As far as I understand, this error should only occur if I try to
      > access a function on a variable that is not an object, but the only
      > variable I am accessing, is $this, and that one is by definition an object,
      > right?
      >
      > Please help!
      >
      > André[/color]

      Comment

      Working...