Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecated function: PHP 8.1 #8

Closed
bogomolov-dev opened this issue Jan 24, 2022 · 3 comments
Closed

Deprecated function: PHP 8.1 #8

bogomolov-dev opened this issue Jan 24, 2022 · 3 comments

Comments

@bogomolov-dev
Copy link

  • 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
Copy link
Contributor

yinx commented Jan 25, 2022

@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
Copy link
Contributor

@alexander-bogomolov v2.1.0 has been released with PHP 8.1 support

@bogomolov-dev
Copy link
Author

@gdebrauwer , thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants