PHP Deprecated: Implicit conversion from float to int loses precision

388 views
Skip to first unread message

david.ma...@gmail.com

unread,
Feb 13, 2023, 1:06:11 PM2/13/23
to JpGraph
Using version 10.2.4, I get errors like

   [13-Feb-2023 11:41:45 America/New_York] PHP Deprecated: Implicit conversion from float 130118.00000000001 to int loses precision in /home/httpd/vhosts/ratingscentral.com/httpdocs/Libraries/jpgraph.php on line 1409

   [13-Feb-2023 11:59:53 America/New_York] PHP Deprecated: Implicit conversion from float 512511.00000000006 to int loses precision in /home/httpd/vhosts/ratingscentral.com/httpdocs/Libraries/jpgraph.php on line 1409

The problem is the line

   srand ((double) microtime() * 1000000);

According to the PHP docs, it is not necessary to call srand. So, I just commented it out.

What is the relationship between version 10.2.4 and version 4.4.1? Is 10.2.4 a beta for 4.4.2?

Here are some other changes I make to the source (I'm targeting HTML5):

   jpgraph.php

    function GetHTMLImageMap($aMapName) {
        // $im = "<map name=\"$aMapName\" id=\"$aMapName\" >\n"; // Commented.
        $im = '<map name="' . $aMapName . '">';                  // Added.

    function GetCSIMImgHTML($aCSIMName, $aScriptName='auto', $aBorder=0 ) {
        if( $aScriptName=='auto' ) {
            $aScriptName=basename($_SERVER['PHP_SELF']);
        }
        $urlarg = $this->GetURLArguments(true);
        // return "<img src=\"".$aScriptName.'?'.$urlarg."\" ismap=\"ismap\" usemap=\"#".$aCSIMName.'" height="'.$this->img->height."\" alt=\"".$this->iCSIMImgAlt."\" />\n"; // Commented.
        return '<img src="'.$aScriptName.'?'.$urlarg.'" usemap="#'.$aCSIMName.'" width="'.$this->img->width.'" height="'.$this->img->height.'" alt="'.$this->iCSIMImgAlt.'">'; // Added.

   jpgraph_plotmark.inc.php

    function AddCSIMCircle($x,$y,$r) {
      ...
            if( !empty($this->csimalt) ) {
                $tmp=sprintf($this->csimalt,$this->yvalue,$this->xvalue);
                // $this->csimareas .= " title=\"$tmp\" alt=\"$tmp\" "; // Commented.
                $this->csimareas .= " title=\"$tmp\" alt=\"$tmp\"";     // Added.
            }
            // $this->csimareas .= " />\n"; // DJM: commented.
            $this->csimareas .= '>';        // DJM: added.

I don't want labels on the top axis, but this doesn't seem to be an opion. So

   jpgraph.php

    function StrokeAxis($aStrokeLabels=true) {
    ...
                // $this->xaxis->Stroke($this->yscale,$aStrokeLabels); // Commented.
                $this->xaxis->Stroke($this->yscale,false);             // Added.

David

w1djm...@gmail.com

unread,
Feb 13, 2023, 1:18:57 PM2/13/23
to JpGraph
My first question would be where did you get a version of JPGraph with a version number of 10.2.4? The "official" version went from 3.x to 4.x quite a while back but there's never been a version 10 AFAIK.

From the description of your problem it sounds like this version 10.2.4 hasn't kept up with PHP changes or the "official" version of JPGraph.

david.ma...@gmail.com

unread,
Feb 13, 2023, 10:02:02 PM2/13/23
to JpGraph
I have 4.4.1-Pro. I switched my website to PHP 8.2. I got errors. The http://jpgraph.net/ website says 4.4 is only supported on PHP 8.1. So, I looked in this group. The thread https://groups.google.com/g/jpgraph/c/0pU_RRA-Gvc pointed me to https://github.com/mitoteam/jpgraph, which is where I found 10.2.4. It works on PHP 8.2 except for the call to srand.

Mikhail Oleynik

unread,
Feb 14, 2023, 1:15:16 AM2/14/23
to JpGraph
https://packagist.org/packages/mitoteam/jpgraph - unofficial composer package of JpGraph library.

JpGraph does not support PHP 8.2 yet. So there are two versions of composer package:
  • 4.4.1 - exact JpGraph library sources as-is with loader and composer.json file added.
  • 10.2.x - same package but with some additional minor patches for it to be compatible with latest PHP (which is 8.2 by now).
As for mentioned "Deprecated: Implicit conversion from float to int loses precision" warnings under php 8.2 this is already fixed in latest package version 10.2.5.
Reply all
Reply to author
Forward
0 new messages