• Resolved trition

    (@trition)


    Dear plugin developer(s),

    After upgrading my website from PHP 7.3 to PHP 8.0 and testing if everything works, I ran into a PHP error that also led to a JS error.

    The loadFile function of the FileHelper class threw an error around line 228, saying that the fread method’s second parameter cannot be zero. This caused the Dashboard settings screen to indicate document.getElementById(“converters”) returns null and document.getElementById(“whitelist”) returns null errors.

    As a (possible) solution, I’ve replaced this part of the loadFile function:

    $handle = @fopen($filename, “r”);
    if ($handle !== false) {
    //Return value is either file content or false
    $return = @fread($handle, filesize($filename));
    fclose($handle);
    }

    with this line:
    $return = file_get_contents($filename);

    This seemingly solved the error. The Settings page loads normally again.
    Do you think this – or something similar – is a possible solution? If so, could this error be fixed in the next patch of the plugin?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author rosell.dk

    (@roselldk)

    Hi,

    Thanks for the fix!
    I haven’t gotten around to testing in PHP 8 yet.

    From what you write, it seems that the problem occurs when the file is empty.
    It seems that the following change would change less, and therefore be less prone to unexpected changes of behavior in edge cases:

               // Return value is either file content or false
                if (filesize($filename) == 0) {
                  $return = '';
                } else {
                  $return = @fread($handle, filesize($filename));
                }
                fclose($handle);

    Can you test it out in php 8 for me? Thanks

    Thread Starter trition

    (@trition)

    Your solution works just as well in PHP 8. I think it’s a good solution.

    Thanks for your assistance! I will mark this topic as resolved now.

    Plugin Author rosell.dk

    (@roselldk)

    Great, thanks again. I hope to release the bug-fix today, but perhaps it will be tomorrow.

    Plugin Author rosell.dk

    (@roselldk)

    Released as 0.19.1

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Error in the FileHelper class after switching to PHP 8.0’ is closed to new replies.