Deprecated function: PHP 8.1
bogomolov-dev opened this issue · 3 comments
bogomolov-dev commented
- Package version: 2.0.0
- PHP version: 8.1
Description:
Deprecated function: Implicit conversion from float 222886.09677419355 to int loses precision in NextApps\UniqueCodes\UniqueCodes->encodeNumber() (line 227 of…/vendor/nextapps/unique-codes/src/UniqueCodes.php).
Code in UniqueCodes:227 generates a float value. This will be cast to interger for using as array key.
Steps To Reproduce:
Just generate a code into a PHP 8.1 environment.
Hotfix
Cast $digit into a integer on line UniqueCodes:229
protected function encodeNumber(int $number)
{
$string = '';
$characters = $this->characters;
for ($i = 0; $i < $this->length; $i++) {
$digit = $number % strlen($characters);
$string = $characters[(int)$digit].$string;
$number = $number / strlen($characters);
}
return $string;
}
yinx commented
@alexander-bogomolov Thanks for the very clear issue report! We have a PR(#7) open at the moment that will fix this and will be merging and tagging a new version soon.
gdebrauwer commented
@alexander-bogomolov v2.1.0 has been released with PHP 8.1 support
bogomolov-dev commented
@gdebrauwer , thanks!