1
WildWillyIII
PHP Error in class.newsstory.php (Stories module)

XOOPS Version: 2.0.15
Module Name/Version: Stories 0.9
PHP Version: 5.0.2
MySQL Version: 4.0.21-nt
Web Server Software (Apache/IIS/Other): Apache 2.0.52
Operating System: Windows XP
Theme you are using: Makes no difference
Custom template: (Yes/No) No
PHP Debug Messages:
le="color: #000000"><?php PHP Fatal error: Using $this when not in object context in C:\xoops-2.0.15\htdocs\modules\stories\class\class.newsstory.php on line 135

MySQL Debug Messages:
Smarty Debug Messages:
A full description of the issue:

I am testing the Stories module for news and have run in to an interesting problem. I have installed the module on our Linux system which is running PHP 4 and it works fine. I have also installed it on my personal development/test machine (Windows XP) that uses PHP 5 and I am getting a blank page when I go in to the News section. When I go to the Admin I can get into Preferences but not Topics Manager or Post/Edit News (they bounce to the index).

When I turned on all debugging there were no errors. The Apache log file has the following error:

le="color: #000000"><?php PHP Fatal error: Using $this when not in object context in C:\xoops-2.0.15\htdocs\modules\stories\class\class.newsstory.php on line 135


From what I can see, the file looks fine. In fact, this is the same file that I copied to the Linux server that is working great. I suspect that this has something to do with the fact that I'm running PHP 5 but I'm not sure what the problem could be.

2
Mithrandir
Re: PHP Error in class.newsstory.php (Stories module)

It is a PHP 5 related problem.

I cannot remember the actual details from when I experienced it first.

I think the problem is that there is a call to $this->something() from within a class function that is called like this:
NewsStory::doSomething()

It is called statically (with :: instead of -> on an object) and then $this doesn't exist in the class function.

Could you paste the whole function code of the function that is around line 135?
"When you can flatten entire cities at a whim, a tendency towards quiet reflection and seeing-things-from-the-other-fellow's-point-of-view is seldom necessary."

Cusix Software

3
WildWillyIII
Re: PHP Error in class.newsstory.php (Stories module)

Thanks Mithandir. That explanation makes sense although I wonder why PHP 4 would let that slide.

Anyway, the following code is the function containing the problem.

le="color: #000000"><?php function getPublished($limit=0, $start=0, $topic=0, $author='', $ihome=0, $asobject=true) { $db =& Database::getInstance(); /*135*/ $this->table = $db->prefix("stories"); $this->topicstable = $db->prefix("topics"); $this->vltable = $db->prefix("vlstories"); $myts =& storiesTextSanitizer::getInstance(); $ret = array(); $sql = "SELECT DISTINCT * FROM ".$this->table.", ".$this->vltable." WHERE ".$this->table.".storyid=".$this->vltable.".storyid AND published > 0 AND published <= ".time()." AND (expired = 0 OR expired > ".time().")"; if ( !empty($topic) ) { $sql .= " AND topicid=".intval($topic); } if ( !empty($author) ) { $sql .= " AND author='".$author."'"; } if ( $ihome == 0 ) { $sql .= " AND ihome=0"; } else { $sql .= " AND (ihome=1 OR ihome=0)"; } if (!empty($uid) && intval($uid) > 0) { $sql .= ' AND uid='.$uid; } $sql .= " ORDER BY tocid DESC"; $result = $db->query($sql,intval($limit),intval($start)); while ( $myrow = $db->fetchArray($result) ) { if ( $asobject ) { $ret[] = new NewsStory($myrow); } else { $ret[$myrow['storyid']] = $myts->makeTboxData4Show($myrow['title']); } } return $ret; }

I added a comment to line 135. When I commented out all references to $this in the function the same error occurred in another function further down in the class.

The problem is more an academic one for me now as I am switching to News 1.44. It has a better submission page than Stories does.

Login

Donat-O-Meter

Stats
Goal: $15.00
Due Date: Jul 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $15.00
Make donations with PayPal!

Latest GitHub Commits