WXforum.net

Web Weather => Weather Website PHP/AJAX scripting => Topic started by: tmabell on March 22, 2021, 12:49:17 PM

Title: WU-History php error
Post by: tmabell 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 (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.
Title: Re: WU-History php error
Post by: saratogaWX 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!
Title: Re: WU-History php error
Post by: tmabell on March 22, 2021, 03:12:46 PM
Thanks for the quick fix Ken!  It's working great now.  =D>
Title: Re: WU-History php error
Post by: tmabell 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?
Title: Re: WU-History php error
Post by: saratogaWX 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);
}
Title: Re: WU-History php error
Post by: tmabell 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.