Author Topic: JPgraph 4.4.0/4.4.1 and PHP 8.1/8.2 errors fixed...  (Read 625 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
JPgraph 4.4.0/4.4.1 and PHP 8.1/8.2 errors fixed...
« on: February 11, 2023, 02:20:51 PM »
It took a bit of digging, but found the magic sauce to get both JPgraph 4.4.0 and 4.4.1 to work on PHP 8.1/8.2 (and likely on PHP 8.0).

Edit {jpgraphdirectory}/src/jpgraph.php

Code: [Select]
function _phpErrorHandler($errno,$errmsg,$filename, $linenum, $vars) {
to

Code: [Select]
function _phpErrorHandler($errno,$errmsg,$filename, $linenum) {
and

Code: [Select]
class LinearTicks extends Ticks {
    public $minor_step=1, $major_step=2;
    public $xlabel_offset=0,$xtick_offset=0;

to

Code: [Select]
class LinearTicks extends Ticks {
    public $minor_step=1, $major_step=2;
    public $ticks_label;
    public $xlabel_offset=0,$xtick_offset=0;

The first fix addresses that the callback function for set_error_handler() removed a prior 5th argument in PHP8.0 (was deprecated in PHP 7.2.0) yielding a Fatal error (wrong number of arguments) with the original code.

The second fix addresses an issue on line 4442 where $this->ticks_label wasn't declared so cast an error.

With these fixes, the sunposa.php script works just fine on either JPgraph version.
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