S1SYPHOS / php-simple-captcha

Simple captcha generator

Home Page:https://codeberg.org/S1SYPHOS/php-simple-captcha

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PHP Deprecated: Implicit conversion from float to int loses precision

JZaaa opened this issue · comments

commented

on php 8.1,

open interpolate show messages

Implicit conversion from float 1.92 to int loses precision [vendor\s1syphos\php-simple-captcha\src\Builder.php, line 638]
Implicit conversion from float 2.88 to int loses precision [vendor\s1syphos\php-simple-captcha\src\Builder.php, line 662]
Implicit conversion from float 0.037696518361372 to int loses precision [in vendor\s1syphos\php-simple-captcha\src\Builder.php, line 455]
....

open applyEffects, when set width=120 and height=48

new Builder($this->phraseBuilder)->build(120, 48);

show messages

Implicit conversion from float 1.92 to int loses precision [in vendor\s1syphos\php-simple-captcha\src\Builder.php, line 638]
 Implicit conversion from float 2.88 to int loses precision [in vendor\s1syphos\php-simple-captcha\src\Builder.php, line 638]
Implicit conversion from float 1.92 to int loses precision [in vendor\s1syphos\php-simple-captcha\src\Builder.php, line 662]
Implicit conversion from float 2.88 to int loses precision [in vendor\s1syphos\php-simple-captcha\src\Builder.php, line 662]

Your code represents v1, this issue is fixed already - how did you install this library? Please upgrade to v2.2 and let me know if that solves the issue. Please not that doing so requires you to change your code as v2 comes with many breaking changes 🦊

commented

v2.2.0 still has this problem

// line 638, line 662
 $effects = mt_rand($surface / 3000, $surface / 2000)

$surface / 3000 and $surface / 2000 may be float, but mt_rand arguments is int

// line 555
 $p = $this->interpolate(
                        $nX - floor($nX), // may be float
                        $nY - floor($nY), // may be float
                        $this->pixel2int(floor($nX), floor($nY)),
                        $this->pixel2int(ceil($nX), floor($nY)),
                        $this->pixel2int(floor($nX), ceil($nY)),
                        $this->pixel2int(ceil($nX), ceil($nY))
);

// private function interpolate(int $x, int $y, int $nw, int $ne, int $sw, int $se);
// interpolate $x, $y is int

Might be a regression .. thanks for spotting that! I'll look into it 😆

@JZaaa Forcing strict types seemed reasonable (and somewhat overdue) so this should be fixed now, a path release under v2.2.1 should be available by now.

If there's anything else, let me know! 💃