googleapis / google-cloud-php

Google Cloud Client Library for PHP
https://cloud.google.com/php/docs/reference
Apache License 2.0
1.1k stars 436 forks source link

Implicit conversion from float 3988292384 to int loses precision Error in PHP 8.1 #6115

Closed devParry closed 1 year ago

devParry commented 1 year ago

Environment details

Steps to reproduce

  1. We are uploading media files on Firebase storage. It was working fine with PHP 7.3 version.
Code example
$object = $bucket->upload(file_get_contents($file), [ 
                                                           'name' => $foldername . '/' . $filename, 
                                                           'metadata' => ['contentType' => $filetype]
                                            ]); 
       $upload_info = $object->info();
  1. But now we have upgraded to PHP 8.1. After the version upgrade, we are facing an error while uploading files. E.g: Message: Implicit conversion from float 3988292384 to int loses precision

    Please check the Screen-shot as well :

    image

Could you please let us know how we can fix this?

Thanks!

bshaffer commented 1 year ago

I've filed an issue with the https://github.com/google/php-crc32 repo here. The function being called here is

    protected function supportsBuiltinCrc32c()
    {
        return Builtin::supports(CRC32::CASTAGNOLI);
    }

And I see nothing wrong with that code. It could be a problem that only occurs on Windows, as I cannot duplicate the warning on Mac OSX or Linux:

var_dump(Google\CRC32\CRC32::CASTAGNOLI);
// int(2197175160)

As this value is an int and not a float, I don't see how the warning could be thrown. Maybe on Windows RC32::CASTAGNOLI is being interpreted as a float?

Edit: The difference in behavior could be dependent on whether or not the crc32c extension is installed.

vishwarajanand commented 1 year ago

Should be fixed now.