vinkla / hashids

A small PHP library to generate YouTube-like ids from numbers. Use it when you don't want to expose your database ids to the user.
https://hashids.org/php
MIT License
5.28k stars 418 forks source link

TypeError: Unsupported operand types: int - string on PHP 8.1 #178

Closed masroore closed 2 years ago

masroore commented 2 years ago

I'm getting the following error:

TypeError: Unsupported operand types: int - string

/path/to/laravel/vendor/hashids/hashids/src/Hashids.php:203
/path/to/laravel/vendor/mtvs/eloquent-hashids/src/HasHashid.php:48
/path/to/laravel/vendor/mtvs/eloquent-hashids/src/HasHashid.php:24
/path/to/laravel/app/Http/Controllers/ItemController.php:13

This is the offending line:

$excess = \mb_strlen($ret) - $this->minHashLength;

Somehow int $minHashLength becomes a string.

FYI, in my config/hashids.php the length parameter is set as an int.

Using PHP 8.1.4 (Laravel 8.83.5)

https://github.com/mtvs/eloquent-hashids/issues/24

vinkla commented 2 years ago

Please submit a pull request with a failing test case.