ryancramerdesign / FieldtypeMapMarker

Fieldtype for ProcessWire - holds an address or location name, and automatically geocodes the address to latitude/longitude using Google Maps API.
http://processwire.com
29 stars 16 forks source link

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

Closed adrianbj closed 5 months ago

adrianbj commented 3 years ago

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

image

cb2004 commented 3 years ago

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

adrianbj commented 3 years ago

@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

andoro commented 2 years ago

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

craigrodway commented 1 year ago

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)) ||
ryancramerdesign commented 9 months ago

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?

cb2004 commented 9 months ago

@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).