Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Fatal error - Using $this when not in object context in

    Hello,
    I am a PHP newby, sorry if this is a lame question.
    I get a Fatal error: Using $this when not in object context in for the following code.

    PHP Code:
    <?php $_row_count = (isset($this->_tpldata['row'])) ? sizeof($this->_tpldata['row']) : 0;if ($_row_count) {for ($_row_i 0$_row_i $_row_count; ++$_row_i){$_row_val = &$this->_tpldata['row'][$_row_i]; ?>
    I looked it up and it seems that its not legal outside of a class. How can I fix this?

    Thanx

  • #2
    Super Moderator
    Join Date
    Feb 2009
    Location
    England
    Posts
    539
    Thanks
    8
    Thanked 63 Times in 54 Posts
    You or I are missing something fundamental. Yes, $this isn't valid there. Where did you get the code? What is _tpldata?
    lamped.co.uk :: Design, Development & Hosting
    marcgray.co.uk :: Technical blog

  • #3
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am trying to do a RSS feed for my phpbb forum.
    tpldata is the twisted way of handling the forum templates. Is there a way to fix this? Is it a syntax problem or is the whole piece of code that needs to be fixed?
    Thanx

  • #4
    Super Moderator
    Join Date
    Feb 2009
    Location
    England
    Posts
    539
    Thanks
    8
    Thanked 63 Times in 54 Posts
    Right, let me try and explain then.

    $blah = new templatecode();

    That just created a "templatecode", stored in $blah. Inside the whole "templatecode" thing, it calls itself "$this", but everyone else calls it "$blah".

    Bit like how the world calls me "Oi, twat", but I call myself Marc.

    If you use $this outside of "templatecode", PHP is thinking "Erm, what the hell is this?!". You need to refer to it by it's proper external name. Might be $template or something. I don't know, but this is a great time to familiarise yourself with PHPBB template objects
    lamped.co.uk :: Design, Development & Hosting
    marcgray.co.uk :: Technical blog

  • #5
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OH,
    OK that for the explication. phpBB is a nightmare. I will see what I can do about this.
    Thanx again


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •