seravo-plugin
seravo-plugin copied to clipboard
Replace substr usage with Compatibility::substr()
Describe the bug
Up to PHP 8.0, substr
used to return empty string on failure. Since PHP 8.0, it returns false
. We have a function (coming in https://github.com/Seravo/seravo-plugin/pull/602) which can handle both of the 2 different cases.
Currently we don't check our substr for failures at all. Eg:
$diff_txt = file_get_contents(substr($screenshot, 0, -4) . '.diff.txt');
will evaluate to:
$diff_txt = file_get_contents('false.diff.txt');
on PHP 8.0 failure and to
$diff_txt = file_get_contents('.diff.txt');
on failure on versions before 8.0.
The compatibility function forces us to check if we had a failure or not.
The error was found by PHPStan but it doesn't complain about it anymore as it thinks we want to have false.diff.txt
etc.