Page 1 of 1

Saratoga Base-* Templates and PHP 8

Posted: Tue 08 Dec 2020 3:28 am
by saratogaWX
I've done testing with the Base-Canada, Base-USA and Base-World templates and only found two scripts that needed minor updates to run on PHP 8.+ (and still compatible with older PHP versions).

common.php V1.11 and flyout-menu.php V1.09 are now available using the update tool with a query of Base-*, Plugin-* 07-Dec-2020

The remaining support scripts seem to work fine and not cast errata in the error_log. It's safe to update before you update PHP to 8.0.0 as the fixes were backward compatible to prior PHP5/PHP7.

Re: Saratoga Base-* Templates and PHP 8

Posted: Tue 08 Dec 2020 5:08 am
by PaulMy
Thanks Ken,
I am all up to date again with scripts for www.komokaweather.com/komokaweather-ca
PHP 7.4 is the latest available on the GoDaddy list so will be a while before I will look at PHP 8.

Enjoy,
Paul

Re: Saratoga Base-* Templates and PHP 8

Posted: Tue 08 Dec 2020 10:08 pm
by ConligWX
Ken to the rescue again. Thank you. :clap:

Re: Saratoga Base-* Templates and PHP 8

Posted: Fri 03 Dec 2021 12:28 am
by N0BGS
Meanwhile, one year later....

I just updated my Linux server to Fedora 35 today which also updated PHP to version 8.0.13. After doing so my home page would no longer display the forecast and wxforecast.php was also blank.

After investigating this a bit I found that the error was caused by a typo on line 537 of advforecast2.php:

Code: Select all

$Status.= "<!-- JSON decode $JSONerror -->\n";
  if (jason_last_error() !== JSON_ERROR_NONE) {
    $Status.= "<!-- content='" . print_r($content, true) . "' -->\n";
  }
Obviously that should be "json_last_error" not "jason." :lol: Why PHP 7.x didn't care about that I don't know.

This seems like an error I may have caused myself rather than Ken since he doesn't make errors, ;) but if it was me I don't remember doing it.

So if you're having a similar problem you may want to check that line.

--Kurt

www.kpw3.com

Re: Saratoga Base-* Templates and PHP 8

Posted: Fri 03 Dec 2021 2:21 am
by BCJKiwi
OK, have made the changes to both files.

Using World and Cumulus files.
However now have an error in PHP 7.4.26 ( and earlier) and PHP 8.1
Undefined variable $string in common.php @ line 502

Code: Select all

<img src="'. $SITE['imagesDir'] . 'flag-'. $k .'.gif" alt="'. $v .'" title="'. $v .'" style="border: none;" /></a>
Have 2 different issues with PHP8
1:-
Deprecated:
Implicit conversion from float4.3111111111111 to int loses precision in CU-defs.php on line 1006
This is here
$dir = $windlabel[ fmod((($winddir + 11) / 22.5),16) ];
the CUdefs file

#-------------------------------------------------------------------------------------
# CU support function - CU_deg2dir - Convert wind direction degrees to cardinal name
#-------------------------------------------------------------------------------------

Code: Select all

function CU_deg2dir ($degrees) {
   // figure out a text value for compass direction
// Given the wind direction, return the text label
// for that value.  16 point compass
   $winddir = $degrees;
   if ($winddir == "n/a") { return($winddir); }

  if (!isset($winddir)) {
    return "---";
  }
  if (!is_numeric($winddir)) {
	return($winddir);
  }
  $windlabel = array ("N","NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S",
	 "SSW","SW", "WSW", "W", "WNW", "NW", "NNW");
  $dir = $windlabel[ fmod((($winddir + 11) / 22.5),16) ];
  return($dir);

} // end function CU_deg2dir
2:-
Also the same Deprecated error but in these lines (in a non Saratoga template addon file for current conditions.

Code: Select all

  $auto .= $langWindShort[ round(($RT_avgbearing +11) / 22.5 % 16)];
  $hybrid .= $langWindShort[ round(($RT_avgbearing +11) / 22.5 % 16)];
Any assistance correcting these issues would be appreciated.
NOTE:- our public websites are still running PHP7 and does not have these updates yet.

Thanks

Re: Saratoga Base-* Templates and PHP 8

Posted: Fri 03 Dec 2021 8:42 pm
by saratogaWX
For common.php lne 502 change it to

Code: Select all

 $string1 = ''; $string = '';
For the CU-defs.php, try

Code: Select all

$dir = $windlabel[ (integer)round(fmod((($winddir + 11) / 22.5),16),0) ];
and see if that fixes the deprecated error.

For the non-saratoga scripts, try

Code: Select all

  $auto .= $langWindShort[ (integer)round(($RT_avgbearing +11) / 22.5 % 16)];
  $hybrid .= $langWindShort[ (integer)round(($RT_avgbearing +11) / 22.5 % 16)];

Re: Saratoga Base-* Templates and PHP 8

Posted: Fri 03 Dec 2021 10:20 pm
by BCJKiwi
OK

@ Line 495 changed
$string1 = '';
to
$string = '';
== success for both php 7 and 8.

Also success with change to CU-defs.php for php 7 and 8

However no joy with change to
$auto .= $langWindShort[ (integer)round(($RT_avgbearing +11) / 22.5 % 16)];
$hybrid .= $langWindShort[ (integer)round(($RT_avgbearing +11) / 22.5 % 16)]; }
which reports the same error in php 8 but OK in php 7

Thanks

Re: Saratoga Base-* Templates and PHP 8

Posted: Sat 04 Dec 2021 12:53 am
by saratogaWX
So, try my same hack with the non-saratoga scripts:

Code: Select all

  $auto .= $langWindShort[ (integer)round(fmod((($RT_avgbearing + 11) / 22.5),16),0)];
  $hybrid .= $langWindShort[ (integer)round(fmod((($RT_avgbearing + 11) / 22.5),16),0)];
Glad the other ones worked out 8-) :D

PHP 8 seems to be more fussed about typing of variables. The round() returns a float value, so (integer)round() makes it an integer for the index in to the wind direction array.
PHP 7 seemed to do the typing-to-integer automatically, PHP 8 insists on having it match the integer index.

Re: Saratoga Base-* Templates and PHP 8

Posted: Sat 04 Dec 2021 2:35 am
by BCJKiwi
Well, That seems to have sorted it.
Thanks V much. :clap: :clap: :clap:

However,
there is ? (was ?) an error with the CU-defs.php fix in php 7. Not sure about php 8 as it is a fleeting value depending on wind direction.

Undefined offset: 16 in CU-defs.php on line 1007
It seems only to occur when the value is 16 - have not seen it on any other value (yet).

Re: Saratoga Base-* Templates and PHP 8

Posted: Sat 04 Dec 2021 2:59 am
by saratogaWX
So maybe the 'round' wasn't such a good idea.

Try

Code: Select all

$dir = $windlabel[ (integer)fmod((($winddir + 11) / 22.5),16) ];
and

Code: Select all

 $auto .= $langWindShort[ (integer)fmod((($RT_avgbearing + 11) / 22.5),16)];
  $hybrid .= $langWindShort[ (integer)fmod((($RT_avgbearing + 11) / 22.5),16)];
then the array selector value will be 0..15 which matches the array size of 16 elements.

Re: Saratoga Base-* Templates and PHP 8

Posted: Sat 04 Dec 2021 5:17 am
by BCJKiwi
Thanks,

Will let it run for a while and report the outcome in due course.

Re: Saratoga Base-* Templates and PHP 8

Posted: Sat 04 Dec 2021 8:12 am
by mcrossley
saratogaWX wrote: Sat 04 Dec 2021 12:53 am PHP 7 seemed to do the typing-to-integer automatically, PHP 8 insists on having it match the integer index.
Actually, I think PHP 8 still does, it is only a deprecation notice not an error. The change will come in PHP 9?

Re: Saratoga Base-* Templates and PHP 8

Posted: Sat 04 Dec 2021 10:21 am
by BCJKiwi
Well, the deprecation warnings were up AND the relevant code was not executed.

Re: Saratoga Base-* Templates and PHP 8

Posted: Sat 04 Dec 2021 12:25 pm
by mcrossley
Hmm, I stand corrected then. But deprecation warnings are normally just that. A warning that something will stop working in a future release, otherwise it is an error.

Re: Saratoga Base-* Templates and PHP 8

Posted: Sat 04 Dec 2021 10:38 pm
by BCJKiwi
@ Mark

You may be correct (partially?) as some things were definitely not working.
The page was some what unreadable with multiple deprecation notices all over the place for different errors despite error notification being turned off.

Have found other issues with php 8.1.0 that do not occur with 8.0.13

It seems 8.1.0 has introduced numerous additional changes.