I've tried to fix just one of the wildwood scripts for PHP 8 .. to get rid of all the PHP warning errors there were multiple changes to be made as PHP 5 was much more forgiving about variables usage than the much more strict PHP 8.
Examples:
$varname[$idx] when $idx is not in the array was treated as a null in PHP 5 with no error, casts a Warning in PHP 8
${varname} syntax is deprecated in PHP 8.2 .. must use {$varname} (except in preg_* function replacement strings, where ${varname} is required)
Here's the changes I had to make for just the wxtempdetails.php to get it to run without error messages:
--- C:\Users\Ken\Documents\saratoga-weather-Website-1and1\wxtemplates\wildwood\WD-wxreports\wxtempdetail.php 2016-06-15 22:56:06.000000000 -0800
+++ C:\xampp\htdocs\USA-wildwood\wxtempdetail.php 2023-01-09 14:34:33.696000000 -0800
@@ -47,6 +47,7 @@
# 2011-12-27 3.6 Added support for Multilingual and Cumulus, Weatherlink, VWS
# 2012-08-26 3.8 Added check for manually provided NOAA data in csv file format
# 2013-08-22 4.0 Updated to allow use without Saratoga templates
+# 2023-01-09 4.1 Updated for PHP 8+ (K. True - Saratoga-weather.org)
############################################################################
$Saratoga_template = !file_exists('nonsaratogatemplate.txt');
if ($Saratoga_template == true){
@@ -460,26 +461,34 @@
echo '<td class="noday" colspan="'.$colspan.'"> </td>';
} else {
- // Get mean temperature data
- $mean = $raw[$mnt][0][$day][$rawlb['mean']] ;
+ // Get mean temperature data
+ if(!isset($raw[$mnt][0][$day][$rawlb['mean']])) {
+ $mean = null;
+ } else {
+ $mean = $raw[$mnt][0][$day][$rawlb['mean']] ;
+ }
if (is_null($mean)){
// if max and min values are available, calculate the mean
- if ((!is_null($raw[$mnt][0][$day][$rawlb['high']])) AND (!is_null($raw[$mnt][0][$day][$rawlb['low']]))){
+ if ((isset($raw[$mnt][0][$day][$rawlb['high']])) AND (isset($raw[$mnt][0][$day][$rawlb['low']]))){
$raw[$mnt][0][$day][$rawlb['mean']] = round((($raw[$mnt][0][$day][$rawlb['high']] + $raw[$mnt][0][$day][$rawlb['low']])/2),1);
$mean = $raw[$mnt][0][$day][$rawlb['mean']] ;
}
- }
+ }
+ if(!isset($tempmonth[$mnt][4])) {$tempmonth[$mnt][4] = 0.0;}
+ if(!isset($tempmonth[$mnt][5])) {$tempmonth[$mnt][5] = 0; }
if (is_numeric($mean)) {
$tempmonth[$mnt][4] = $tempmonth[$mnt][4] + $mean;
$tempmonth[$mnt][5] = $tempmonth[$mnt][5] + 1;
}
- if ( $raw[$mnt][0][$day][$rawlb['high']] == "" ) {
+ if ( !isset($raw[$mnt][0][$day][$rawlb['high']]) ) {
$put = "---";
} else {
$put = $raw[$mnt][0][$day][$rawlb['high']];
- $put = roundoff($put, $round);
+ $put = roundoff($put, $round);
+ if(!isset($tempmonth[$mnt][0])) {$tempmonth[$mnt][0] = 0.0;}
+ if(!isset($tempmonth[$mnt][1])) {$tempmonth[$mnt][1] = 0; }
$tempmonth[$mnt][0] = $tempmonth[$mnt][0] + $put;
$tempmonth[$mnt][1] = $tempmonth[$mnt][1] + 1;
if ($put > $monthmax[$mnt]) {
@@ -494,10 +503,12 @@
}
- if ( $raw[$mnt][0][$day][$rawlb['low']] == "" ) {
+ if ( !isset($raw[$mnt][0][$day][$rawlb['low']]) ) {
$put = "---";
} else {
$put = $raw[$mnt][0][$day][$rawlb['low']];
+ if(!isset($tempmonth[$mnt][2])) {$tempmonth[$mnt][2] = 0.0;}
+ if(!isset($tempmonth[$mnt][3])) {$tempmonth[$mnt][3] = 0; }
$tempmonth[$mnt][2] = $tempmonth[$mnt][2] + $put;
$tempmonth[$mnt][3] = $tempmonth[$mnt][3] + 1;
if ($put < $monthmin[$mnt]) {
@@ -551,7 +562,7 @@
echo '</td>';
for ( $i = 0 ; $i < 12 ; $i++ )
{
- if ($tempmonth[$i][1] > 0)
+ if (isset($tempmonth[$i][1]) and $tempmonth[$i][1] > 0)
{
echo '<td class=" ' . ValueColor($monthmax[$i]).'" colspan="'.$colspan.'">' . sprintf($places,$monthmax[$i]) .' </td>';
}
@@ -567,7 +578,7 @@
echo '</td>';
for ( $i = 0 ; $i < 12 ; $i++ )
{
- if ($tempmonth[$i][1] > 0)
+ if (isset($tempmonth[$i][1]) and $tempmonth[$i][1] > 0)
{
echo '<td class=" ' . ValueColor(($tempmonth[$i][0] / $tempmonth[$i][1] )).'" colspan="'.$colspan.'">' . sprintf($places,($tempmonth[$i][0] / $tempmonth[$i][1] )) . '</td>';
}
@@ -594,7 +605,7 @@
echo '</td>';
for ( $i = 0 ; $i < 12 ; $i++ )
{
- if ($tempmonth[$i][3] > 0)
+ if (isset($tempmonth[$i][3]) and $tempmonth[$i][3] > 0)
{
echo '<td class=" ' . ValueColor(($tempmonth[$i][2] / $tempmonth[$i][3] )).'" colspan="'.$colspan.'">' . sprintf($places,($tempmonth[$i][2] / $tempmonth[$i][3] )) . '</td>';
}
@@ -611,7 +622,7 @@
for ( $i = 0 ; $i < 12 ; $i++ )
{
- if ($tempmonth[$i][3] > 0)
+ if (isset($tempmonth[$i][3]) and $tempmonth[$i][3] > 0)
{
echo '<td class=" ' . ValueColor($monthmin[$i]).'" colspan="'.$colspan.'">' . sprintf($places,$monthmin[$i]) . '</td>';
}
You get the general idea.. somebody else can slog through the various scripts making those type of code changes.. I'm tired..