I'm getting a PHPStan error that I don't understand how to fix:
Parameter #1 $length of function random_bytes expects int<1, max>, int given.
The function is very simple:
private function generateEncryptionKey(int $bytes = 16): string {
return bin2hex(random_bytes($bytes));
}
I don't know why the error is expects int<1, max>
because I typehint $bytes
to int
and random_bytes takes an int as the argument.
So what is the meaning of the error PHPStan is identifying here, and how can I fix it?
The PHPStan online demo also reports this as an error.