Author Topic: menubar.php error - foreach()  (Read 1157 times)

0 Members and 1 Guest are viewing this topic.

Offline W3DRM

  • Forecaster
  • *****
  • Posts: 3360
    • Emmett Weather
menubar.php error - foreach()
« on: January 13, 2018, 02:19:41 PM »
Just noticed that I am getting an error that shows up in the menubar.php code. It seems to be saying there is something wrong with the foreach() statement. I've attached a screen capture of what the menu error looks like. No changes to the menubar.php file have been in many months.

I am running the latest versions of everything. All routines are current, based on the check-fetch-times.php?show=versions code. All Win10 updates are current too. Am running PHP v7.1.13. Don't know when this actually started as I didn't notice it until this morning. I see the same error on multiple computers and various browsers.
Don - W3DRM - Emmett, Idaho --- Blitzortung ID: 808 --- FlightRadar24 ID: F-KBOI7
Davis Wireless VP2, WD 10.37s150,
StartWatch, VirtualVP, VPLive, Win10 Pro
--- Logitech HD Pro C920 webcam (off-line)
--- RIPE Atlas Probe - 32849

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9257
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: menubar.php error - foreach()
« Reply #1 on: January 13, 2018, 02:58:11 PM »
Hi Don,
Your nws-alerts.php is reporting
Quote
Warning: A non-numeric value encountered in /homepages/14/d239618093/htdocs/nws-alerts.php on line 127

Warning: Illegal string offset 'Greater Lake Tahoe Area (NV)' in /homepages/14/d239618093/htdocs/nws-alerts.php on line 219

Warning: Illegal string offset 'Greater Reno, Carson City, Minden' in /homepages/14/d239618093/htdocs/nws-alerts.php on line 219

Fatal error: Uncaught Error: [] operator not supported for strings in /homepages/14/d239618093/htdocs/nws-alerts.php:306 Stack trace: #0 {main} thrown in /homepages/14/d239618093/htdocs/nws-alerts.php on line 306
Your site is running PHP Version: 7.1.13 .
Looks like some more initialization changes need to be made to the nws-alerts.php V1.37 script.  Change
Code: [Select]
// set variables
$ad      = '';
$vCodes  = '';
$noAlrt  = '';
$cmyzc   = '';
$aBox    = '';
$box     = '';
$atData  = '';
$noData  = '';
$WA      = '1';
$logData = '';
$Status  = '';
$fltrd   = '^FF';
$ai      = array();
$bi      = array();
$noA     = array();
$codeID  = array();
$ano     = array();
$norss   = array();
$abData  = array();
$rssData = array();
$adnoBI  = array();
$uts = date("U");     // current unix time stamp
$timenow = date("D m-j-Y g:i a",$uts);
to
Code: [Select]
// set variables
$ad      = array();
$vCodes  = '';
$noAlrt  = array();
$cmyzc   = '';
$aBox    = '';
$box     = '';
$atData  = array();
$noData  = false;
$WA      = '1';
$logData = array();
$Status  = '';
$fltrd   = '^FF';
$ai      = array();
$bi      = array();
$noA     = array();
$codeID  = array();
$ano     = array();
$norss   = array();
$abData  = array();
$rssData = array();
$adnoBI  = array();
$uts = date("U");     // current unix time stamp
$timenow = date("D m-j-Y g:i a",$uts);

Curly was using null strings to initialize most variables.  PHP7 dislikes changing type (string) to (array) and so barfs at it.  The fix is to initialize the variables to the correct type.
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline W3DRM

  • Forecaster
  • *****
  • Posts: 3360
    • Emmett Weather
Re: menubar.php error - foreach()
« Reply #2 on: January 13, 2018, 04:34:01 PM »
Aha, I just moved to PHP v7.1.13 about a week ago so that is probably what triggered the errors.

Thanks for the quick resolution! Will make the change a little later this afternoon. I'm sharpening my wife's kitchen knives at the moment and probably shouldn't stop...  ;)
Don - W3DRM - Emmett, Idaho --- Blitzortung ID: 808 --- FlightRadar24 ID: F-KBOI7
Davis Wireless VP2, WD 10.37s150,
StartWatch, VirtualVP, VPLive, Win10 Pro
--- Logitech HD Pro C920 webcam (off-line)
--- RIPE Atlas Probe - 32849

Offline W3DRM

  • Forecaster
  • *****
  • Posts: 3360
    • Emmett Weather
Re: menubar.php error - foreach()
« Reply #3 on: January 13, 2018, 06:32:04 PM »
Okay, I updated the nws-alerts.php file but the issue remains. I've checked to make sure the new code did, in fact, get uploaded and it did. I've also refreshed the page too without any luck. Additionally, the CRON job is running.
Don - W3DRM - Emmett, Idaho --- Blitzortung ID: 808 --- FlightRadar24 ID: F-KBOI7
Davis Wireless VP2, WD 10.37s150,
StartWatch, VirtualVP, VPLive, Win10 Pro
--- Logitech HD Pro C920 webcam (off-line)
--- RIPE Atlas Probe - 32849

Offline tmabell

  • Forecaster
  • *****
  • Posts: 394
    • Mishawaka Weather
Re: menubar.php error - foreach()
« Reply #4 on: January 15, 2018, 02:23:06 PM »
I don't know if this is relevant but I am using PHP 7.2 and I've not experienced any errors.  For what it's worth this is my section that Ken referenced:

Code: [Select]
// set variables
$ad      = '';
$vCodes  = '';
$noAlrt  = '';
$cmyzc   = '';
$aBox    = '';
$box     = '';
$atData  = '';
$noData  = '';
$WA      = '1';
$logData = array();
$Status  = '';
$fltrd   = '^FF';
$ad      = array();
$noAlrt  = array();
$ai      = array();
$bi      = array();
$noA     = array();
$codeID  = array();
$ano     = array();
$norss   = array();
$abData  = array();
$rssData = array();
$adnoBI  = array();
$atData  = array();
$uts = date("U");     // current unix time stamp
$timenow = date("D m-j-Y g:i a",$uts);

Offline W3DRM

  • Forecaster
  • *****
  • Posts: 3360
    • Emmett Weather
Re: menubar.php error - foreach()
« Reply #5 on: January 15, 2018, 07:07:37 PM »
Now I am baffled - the problem has gone away. I no longer see any errors in my menu. So, whatever it was, has disappeared, for the time being. Will keep a watch on it. Thanks for the help and feedback.
Don - W3DRM - Emmett, Idaho --- Blitzortung ID: 808 --- FlightRadar24 ID: F-KBOI7
Davis Wireless VP2, WD 10.37s150,
StartWatch, VirtualVP, VPLive, Win10 Pro
--- Logitech HD Pro C920 webcam (off-line)
--- RIPE Atlas Probe - 32849