Administrators ProAvia Posted December 15, 2016 Administrators Report Posted December 15, 2016 On 11/28/2016 at 0:18 PM, TAV1702 said: I got the news to produce today. Now on to fix that dreaded "this" error. Hi Ray Any luck on solving the "this" error? I'm getting it with the PopUpNews module and the Screenshots module. I get the news and random screenshot to show, but the error displays just above each item. Deprecated: Non-static method PopUpNews::PopUpNewsList() should not be called statically, assuming $this from incompatible context in ..... layout.php Deprecated: Non-static method Screenshots::show_random_screenshot() should not be called statically, assuming $this from incompatible context in ... layout.php phpVMS 5.5.2 - latest PopUpNews and Screenshots modules - PHP 5.6.18 Thanks for any insight! Gene Quote
Sava Posted December 15, 2016 Report Posted December 15, 2016 Open up the PopUpNews and Screenshots file in core/common and find the following: public function PopUpNewsList () ... change to public static function PopUpNewsList () ... Notice the word 'static' between public and function. Add it ;). Same for Screenshots. Quote
Administrators ProAvia Posted December 15, 2016 Administrators Report Posted December 15, 2016 (edited) Thanks for the reply Sava I'll stick just to the PopUpNews module here..... The 'PopUpNewsData.class.php' in core/common already has the 'static' wording - but there is no 'PopUpNewsList ()...' in that file. <?php //simpilotgroup addon module for phpVMS virtual airline system // //simpilotgroup addon modules are licenced under the following license: //Creative Commons Attribution Non-commercial Share Alike (by-nc-sa) //To view full icense text visit http://creativecommons.org/licenses/by-nc-sa/3.0/ // //@author David Clark (simpilot) //@copyright Copyright (c) 2009-2012, David Clark //@license http://creativecommons.org/licenses/by-nc-sa/3.0/ class PopUpNewsData extends CodonData { public static function popupnewsitem($id) { $query = 'SELECT * FROM ' . TABLE_PREFIX .'news WHERE id=' . DB::escape($id) . ' '; return DB::get_row($query); } public static function get_news_list($howmany) { $sql = 'SELECT id, subject, body, postedby, UNIX_TIMESTAMP(postdate) AS postdate FROM ' . TABLE_PREFIX .'news ORDER BY postdate DESC LIMIT '.DB::escape($howmany); return DB::get_results($sql); } } However, the 'PopUpNews.php' in core/modules has the 'PopUpNewsList ()...' item. But when I add 'static' to that line, only my background image and header show - with an error of Fatal error: Using $this when not in object context in /home/xxxxxx/public_html/xxxxxxxxxx/phpvmsTEST2/core/modules/PopUpNews/PopUpNews.php on line 33. Here is the content of that file - without the 'static'. <?php //simpilotgroup addon module for phpVMS virtual airline system // //simpilotgroup addon modules are licenced under the following license: //Creative Commons Attribution Non-commercial Share Alike (by-nc-sa) //To view full icense text visit http://creativecommons.org/licenses/by-nc-sa/3.0/ // //@author David Clark (simpilot) //@copyright Copyright (c) 2009-2012, David Clark //@license http://creativecommons.org/licenses/by-nc-sa/3.0/ class PopUpNews extends CodonModule { public function popupnewsitem($id) { $id = intval($id); if(!is_numeric($id)){header('Location: '.url('/'));} $result = PopUpNewsData::popupnewsitem($id); $this->title = $result->subject; Template::Set('item', $result); Template::Show('popupnews/popupnews_item'); } public function PopUpNewsList($howmany = 5) { $howmany = intval($howmany); if(!is_numeric($howmany)){exit;} $res = PopUpNewsData::get_news_list($howmany); $this->set('news', $res); $this->show('popupnews/popupnews_list'); echo '<div style="text-align: center; font-size: 10px;"><a href="http://www.simpilotgroup.com">PopUpNews © simpilotgroup.com</a></div>'; } } I am using phpVMS 5.5.2, skin is 'vairline' and PopUpNews is called in the layout.php as <div id="box"> <h3><font color="#0066FF">FreedomAir NOTFAP's</font></h3> <?php PopUpNews::PopUpNewsList(5); ?> </div> Does all this look correct? Could the issue be related to the skin itself? Edited December 15, 2016 by ProAvia Quote
TAV1702 Posted December 16, 2016 Report Posted December 16, 2016 Ill have to go look at what I did. I am not sure to be honest. I know the static was already there and when I removed it, one error went away and I got the dreaded $this error. I do have this working on my site. I might have just suppressed the error I'll go look and report back here in a short. Quote
Administrators ProAvia Posted December 16, 2016 Administrators Report Posted December 16, 2016 Yeah - i could suppress the error, but would rather have a way to fix it. Wanted to fix this one first and possibly use the same fix on other modules as well. I guess worst case would be to fix all the strict standards errors with older - not updated - modules and then suppress all of this type. If there were an easy fix out there, we'd probably know of it by now. Quote
TAV1702 Posted December 16, 2016 Report Posted December 16, 2016 (edited) 32 minutes ago, ProAvia said: Yeah - i could suppress the error, but would rather have a way to fix it. Yep, exactly. I rarely to never suppress errors. I would rather fix. This was one I might not have fixed. Sorry i got caught up with household stuff. I am free now and am going to go look at code. 32 minutes ago, ProAvia said: If there were an easy fix out there, we'd probably know of it by now. Yeah, I have to agree. Many modules I went round and round with. Fixing strict errors only to be met with he $this error. Some of them I fought for days on end. I went to Stackoverflow thinking that there are so many gurus there surely there would be an answer, NOPE! 9 out of 10 replies were to suppress errors. **EDIT** Ok I checked all the files and I do not have suppression anywhere in popup news module. I apologize as I can not for the life of me think of what I did to make it work. If I can think of any reason at all I will gladly come back and post. Edited December 16, 2016 by TAV1702 Additional Info Quote
Administrators ProAvia Posted December 16, 2016 Administrators Report Posted December 16, 2016 Thanks for looking Ray! I'm just now getting around to upgrading from version 2.x to 5.5.2 . Quite the challenge - and maybe I'll even learn something... LOL I do know on my live version 2.x phpVMS, that when our host upgraded to php 5.6, we had a ton of errors. Many were fixed (not by me though) by suppressing the error. Quote
TAV1702 Posted December 16, 2016 Report Posted December 16, 2016 (edited) Yeah 5.6 really changed the game for us as far as phpVMS goes. Wait until php 7 and mySQL 5.7 ;-) It won't even install then...... yet. I am still digging though. I might have put a suppression somewhere in the files and I can't find it but that is not like me to do such a thing. I normally try to fix. I just compared my popup news module files to the default download zip file from David and it is all but basically the same minus copyright he gave me permission to not remove but "Move" earlier on in this forum. Edited December 16, 2016 by TAV1702 Quote
web541 Posted December 16, 2016 Report Posted December 16, 2016 Try calling it like this (might not work for your version) <?php $allnews = new PopUpNews(); $allnews->PopUpNewsList(5); ?> Instead of this <?php PopUpNews::PopUpNewsList(5); ?> Which should eliminate (or at least hide) the $this error and also calls the function statically, this works for me on PHP 5.6.8 If you want my final version but not much has changed, just the way it's accessed. 1 Quote
Administrators ProAvia Posted December 17, 2016 Administrators Report Posted December 17, 2016 (edited) Thanks web541 - that works great! First I used your revised call - and that worked to get rid of the error. Then I added your modified '... core/modules/PopUpNews/PopUpNews.php' file - and the error is still gone. The only reason I added your modded php file was to preclude other issues in the future. Now to figure out exactly what your did and why. Then off to see if I can fix basically the same issue in the Screenshots module. Thanks again!! EDIT: Screenshots module fix same way Called as $allpics = new Screenshots (); $allpics->show_random_screenshot(); Instead of Screenshots::show_random_screenshot(); Will post that in the Screenshots thread also in case it helps someone else out. Edited December 17, 2016 by ProAvia added Screenshots edits Quote
TAV1702 Posted December 17, 2016 Report Posted December 17, 2016 Nice work boys. This error has come up in a few other modules as well. I wonder if ti will work in them to? Quote
Administrators ProAvia Posted December 17, 2016 Administrators Report Posted December 17, 2016 1 hour ago, TAV1702 said: Nice work boys. This error has come up in a few other modules as well. I wonder if ti will work in them to? I think we'll find out in the next few days! Now that these 2 are fixed, I can test out the other modules I have. Let us know if you fix any also. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.