View Full Version : Fatal error - Using $this when not in object context in

10-29-2009, 12:28 AM
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 $_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?


10-29-2009, 12:38 AM
You or I are missing something fundamental. Yes, $this isn't valid there. Where did you get the code? What is _tpldata?

10-29-2009, 12:44 AM
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?

10-29-2009, 12:49 AM
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 :D

10-29-2009, 12:54 AM
OK that for the explication. phpBB is a nightmare. I will see what I can do about this.
Thanx again