FieldtypeMapMarker icon indicating copy to clipboard operation
FieldtypeMapMarker copied to clipboard

round(): Argument #1 ($num) must be of type int|float, string given with PHP8

Open adrianbj opened this issue 4 years ago • 6 comments

It's impossible to save a page with a MM field in PHP 8 because of this error:

image

adrianbj avatar Feb 28 '21 17:02 adrianbj

@adrianbj @ryancramerdesign same issue, I am also wondering why the decimal places are limited to 4 anyway?

cb2004 avatar Jul 01 '21 11:07 cb2004

@cb2004 - strange thing is that I can't seem to reproduce this anymore. I've tried googling to see if more recent versions of PHP8 have relaxed this or not, but haven't found anything yet.

Testing via Tracy I see this, so it's like it doesn't care about it being a string anymore - I'm confused :)

image

adrianbj avatar Jul 01 '21 14:07 adrianbj

I got the same error now.

My PHP version is 8.0.14 ProcessWire version is 3.0.192 Map Marker is 2.0.9

Going back to PHP 7.4.27 solves the issue. Do you need any additional info regarding the bug?

image

andoro avatar Jan 10 '22 01:01 andoro

Changing the code to explicitly cast the values worked for me:

$lat = (float) $input["_{$name}_lat"];
$lng = (float) $input["_{$name}_lng"];

$precision = 4; 
$this->defaultLat = (float) $this->defaultLat;
$this->defaultLng = (float) $this->defaultLng;

if(	((string) round($lat, $precision)) != ((string) round($this->defaultLat, $precision)) ||

craigrodway avatar Jan 11 '23 10:01 craigrodway

Thanks, I've pushed an update that uses @craigrodway suggestion and also updated the module to be PW 3.x native. Though haven't been able to test properly as my previous maps API keys don't seem to work anymore and Google is asking me for money to get a new key. Can anyone with a key confirm that this update fixes the issue?

ryancramerdesign avatar Dec 28 '23 15:12 ryancramerdesign

@ryancramerdesign the issue seemed to just disappear for me if I remember correctly. With the API, you just supply credit card details and it will only charge if you go over the free uses per month (which is quite a lot).

cb2004 avatar Jan 04 '24 08:01 cb2004