Author Topic: Heads up - PHP 8.2 has a deprecation for variable definitions of ${varname}  (Read 693 times)

0 Members and 1 Guest are viewing this topic.

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
I've just started testing the Saratoga templates and scripts and found that PHP 8.2 has a deprecation for a variable naming the is used in many of my (and others) scripts:

Quote
"${var}" and "${expr}" style interpolation

The "${var}" and "${expr}" style of string interpolation is deprecated.
Use "$var"/"{$var}" and "{${expr}}", respectively.

This means that all ${varname} have to be changed to {$varname} throughout the scripts.  It's as simple as doing a global find for "${" and replacing it with "{$" and it is backwards compatible to PHP 5.6 (in my testing).
I'll be updating all my scripts with this shortly.

If you update your site to PHP 8.2 before I finish the updates, be sure to turn off E_DEPRECATED in php error_reporting to not flood your error messages in your log (or displays on your website if display_errors is on).
« Last Edit: December 27, 2022, 01:37:42 PM by saratogaWX »
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 saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
I finished with the updates to the 'stock' Saratoga templates and they're now available on the update tool page for 27-Dec-2022.  Use your Base and Plugin for the query.

Here's the summary of the updates (by Base, then Plugin):

Version 3.376 - 27-Dec-2022
(Base-*) script updates for PHP 8.2+ to ajax-dashboard V1.31, ajax-gizmo V1.15, common V1.14, flyout-menu V1.10, get-metar-conditions-inc V1.20, get-USNO-sunmoon V3.05, include-metar-display V1.07, thermometer V1.19;

(Base-Canada) script updates for PHP 8.2+ to ec-forecast V5.04, ec-lightning V1.04;

(Base-USA) script updates for PHP 8.2+ to advforecast2 V5.19, atom-advisory V2.14, atom-top-warning V2.12, nws-alerts-details-inc V1.08, radar-status V1.20, wxadvisory V1.04;

(CU-plugin,VWS-plugin,WEEWX-plugin,WL-plugin,WV-plugin) script updates for PHP 8.2+ to include-NOAA-reports V2.08, wxnoaaclimatereports V1.02;

I'm now looking at the legacy scripts for similar updates if needed.
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 zmarfak

  • Contributor
  • ***
  • Posts: 135
    • Matar
Ken,
thank you for the work, installed the scripts, have no problems (running php 8.0.26)
Patrick
Davis Vantage Pro2 with a Meteobridge NANO SD and WL (6.04) on a Intel NUC 
https://www.matar.be

Offline dwhitemv

  • KORJUNCT3
  • Member
  • *
  • Posts: 36
    • My PWS on Weather Underground
Sorry, but in the 12/27/2022 update, get-metar-conditions-inc.php line 231 has a place where ${1} was changed to {$1} incorrectly. preg_replace() does not use PHP string type interpolation, it still uses the shell style delimiters. The brackets are unnecessary in that location (the backreference isn't followed by a digit) and can be removed. There is some commented-out code just below the block on lines 236-237 that has the same issue.

Example code:
<?php
$metar = '23453 KT XYZ ABC';
$out = preg_replace('|(\d{5}) KT|i', '${1}KT', $metar); // v1.19
echo $out, "\n";
$out = preg_replace('|(\d{5}) KT|i', '{$1}KT', $metar); // v1.20
echo $out, "\n";
$out = preg_replace('|(\d{5}) KT|i', '$1KT', $metar); // Alternate
echo $out, "\n";


Result:
23453KT XYZ ABC
{23453}KT XYZ ABC
23453KT XYZ ABC


Fiddle:
https://onlinephp.io?s=s7EvyCjg5VLJTS1JLFKwVVA3MjYxNVbwDlGIiIxScHRyVrcGyuaXlgDlCopS0-OLUgtyEpNTNdRrNGJSqk1rNYFqazLVdRTUVaoNa71DgCyIYZrWCvr6CmWGeoaWvFypyRn5CiBjdBSUYvKUiDazWgW7mUYG5JupYohhomNOSWpRXmJJKjZTAQ%2C%2C&v=8.2.0

Thanks for your hard work on the templates!

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Do you mean the line
Code: [Select]
$metar = preg_replace('|(\d{5}) KT|i', '{$1}KT', $metar); // fix any space in wind value
should remain as
Code: [Select]
$metar = preg_replace('|(\d{5}) KT|i', '${1}KT', $metar); // fix any space in wind value as it was in V1.19.

I'll revert it in V1.21.. thanks for the heads-up!
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 saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Updated in the distributions .. use the update tool for Base-*, *-Plugin, 03-Jan-2023.
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