Author Topic: WU-History php error  (Read 445 times)

0 Members and 1 Guest are viewing this topic.

Offline tmabell

  • Forecaster
  • *****
  • Posts: 394
    • Mishawaka Weather
WU-History php error
« on: March 22, 2021, 12:49:17 PM »
Since I began using php8 I have found a few scripts that don't like it much.  The WU-History-inc.php is one of them.  I'm using Ken's version 3.4g dated 27 April 2020. 

Here is my page:  https://mymishawakaweather.com/History.php  The Daily & Weekly data populate correctly.  The problem can be seen by choosing "Month" or Year". 

This is the error: 
Code: [Select]
Fatal error: Uncaught TypeError: mktime(): Argument #4 ($month) must be of type ?int, string given in C:\www\WU-History-inc.php:1433 Stack trace: #0 C:\www\WU-History-inc.php(1433): mktime(0, 0, 0, '3-', 1, '2020') #1 C:\www\WU-History-inc.php(1018): AddDate('3-', '1', '2020', 0) #2 C:\www\History.php(218): include('C:\\www\\WU-Histo...') #3 {main} thrown in C:\www\WU-History-inc.php on line 1433
I have turned on error reporting which adds five lines at the top of the script.

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9278
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: WU-History php error
« Reply #1 on: March 22, 2021, 01:46:26 PM »
That was an easy fix.

I changed
Code: [Select]
$pmo = substr($data, 5, 2);
to
Code: [Select]
$pmo = substr($data, 5, 2);
$pmo = str_replace('-','',$pmo);

I updated https://github.com/ktrue/WU-History distribution with WU-History-inc.php V3.4h - 21-Mar-2021 with that fix.

Thanks for reporting it!
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 tmabell

  • Forecaster
  • *****
  • Posts: 394
    • Mishawaka Weather
Re: WU-History php error
« Reply #2 on: March 22, 2021, 03:12:46 PM »
Thanks for the quick fix Ken!  It's working great now.  =D>

Offline tmabell

  • Forecaster
  • *****
  • Posts: 394
    • Mishawaka Weather
Re: WU-History php error
« Reply #3 on: March 23, 2021, 08:23:03 AM »
This morning another glitch popped up:

Code: [Select]
Fatal error: Uncaught DivisionByZeroError: Division by zero in C:\www\WU-History-inc.php:1300 Stack trace: #0 C:\www\WU-History-inc.php(689): wDirAvg(Array) #1 C:\www\History.php(218): include('C:\\www\\WU-Histo...') #2 {main} thrown in C:\www\WU-History-inc.php on line 1300
This is on the Daily display which worked fine yesterday?

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9278
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: WU-History php error
« Reply #4 on: March 23, 2021, 10:56:37 AM »
I think you can fix it by changing 1299 in your WU-History-inc.php from
Code: [Select]
return round($tot / $num,0);
to
Code: [Select]
if($num>0) {
  return round($tot / $num,0);
} else {
  return(0);
}
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 tmabell

  • Forecaster
  • *****
  • Posts: 394
    • Mishawaka Weather
Re: WU-History php error
« Reply #5 on: March 23, 2021, 12:41:04 PM »
I didn't catch it in time to test that change because by 12:30 PM local time, the problem had gone away on its own.   ](*,)  I did change the code so time will tell.

Thank you for checking into this again.