JimChenWYU / yii2-hashids

:rainbow:Hashids for Yii framework
MIT License
5 stars 1 forks source link

Implicit conversion error #1

Open srakl opened 2 years ago

srakl commented 2 years ago

I'm getting this error on php version 8.1.1

Implicit conversion from float 20.5 to int loses precision

it works fine on php 8.0.8

error is on this code

    public static function getDataUrl($model) {
       return Url::to(['/report/default/view', 'id' => Yii::$app->hashids->encode($model->id)], true);
   }

Where $model->id is the row id the in a table and is an int. So far im getting the error for id 766

srakl commented 2 years ago

i narrowed down the problem to hashids.php line 241.

$ret = substr($ret, $excess / 2, $this->_min_hash_length);

where

$ret = mz1xVX2WLMBPO4Gw7N5QDybzz2b9J6ZdpERa8Kegjl3Yo0vAr
$excess = 41
$this->_min_hash_length = 8
JimChenWYU commented 2 years ago

Thanks your report, I will handle it later.

JimChenWYU commented 2 years ago

https://github.com/vinkla/hashids/issues/179

I find same issues from vinkla/hashids

In fact, I dont know php8 or higher, but I find the signature of substr from https://www.php.net/manual/en/function.substr.php

substr(string $string, int $offset, ?int $length = null): string

the second parameter is marked as the type of int, so it's not Compatible with php8.0

Maybe I should upgrade the library to fix this

JimChenWYU commented 2 years ago

Maybe you should know only hashids/hashids:4.1.0 support php8 or higher now.