Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-77185

PHP 8 error when disk_free_space function is disabled

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • 4.2.8, STABLE backlog, 4.1.1, 4.1.11, 4.3.5, 4.4, 4.4.1
    • Libraries
    • MOODLE_401_STABLE, MOODLE_402_STABLE, MOODLE_403_STABLE, MOODLE_404_STABLE
    • main
    • Hide
      1. Setup your hosting to use PHP 8.0 or greater.
      2. Setup your hosting php.ini to disable the function disk_free_space (disable_functions).
      3. Restart your webserver to update php settings and try access to Moodle.
      4. You will receive the reported error.
      Show
      Setup your hosting to use PHP 8.0 or greater. Setup your hosting php.ini to disable the function disk_free_space (disable_functions). Restart your webserver to update php settings and try access to Moodle. You will receive the reported error.

      Description

      When using PHP 8+ with the function "disk_free_space" disabled, this throws the following error:

      Exception - Call to undefined function core\session\disk_free_space()

      Cause

      The error handling of the "@" character has changed with PHP 8 and PHP 8.1. If functions are addressed that are deactivated on the server side, a fatal error occurs even if this function is provided with an "@".
       
      In this case, it happens in the following file:

      /lib/classes/session/file.php:67

      $freespace = @disk_free_space($this->sessiondir);

       

      Solution

      in PHP 8+ we must check the function with "function_exists" implicit and not use "@", because in shared hosting some php functions could be disabled.

      Change the mentioned line code with:

      $freespace = function_exists('disk_free_space') ? disk_free_space($this->sessiondir) : false;

      Github Compare for pull-request: https://github.com/moodle/moodle/compare/main...fedealvz:moodle:main

       

       

            Unassigned Unassigned
            fedealvz Federico Alvarez
            Leon Stringer Leon Stringer
            Votes:
            2 Vote for this issue
            Watchers:
            15 Start watching this issue

              Created:
              Updated:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 minute
                1m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.