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

Make Moodle code compatible with Exception/Throwable changes in PHP7

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.0, 3.1
    • Fix Version/s: 3.0.1
    • Component/s: General
    • Labels:
    • Testing Instructions:
      Hide

      Basically what you need to do here is to make sure that we continue to correctly process php engine recoverable errors. Typical example of such error is passing an argument to the function that has different type than typehint. Example

      function myfunc(stdClass $a) {}
      myfunc('iamnotaclass');
      

      https://3v4l.org/BWIsO
      https://3v4l.org/MOJuD

      In PHP5 this is an error, that is caught by our default_error_handler() and converted to coding_exception.

      In PHP7 it is NOT an error and never gets to the default_error_handler(), it is a special engine exception that goes straight to our default_exception_handler(). However it does not have type Exception, it has type TypeError which extends Throwable.

      You need to manually insert the bad code (both normal exception and typeerror) in some places and make sure we process them correctly in the following cases:

      • unittests (it correctly reports failure)
      • behat (it correctly reports failure)
      • delegated transaction (that has to be rolled back on error/exception)
      • install/upgrade code - error/exception terminates the upgrade process and adds an entry to the error log

      Bonus here is that the errors that were fatal in PHP5 (for example, trying to initiate an instance of non-existing class) become Throwable's in PHP7 and they are caught by the default_exception_handler(). This resolves MDL-46514 for example

      Show
      Basically what you need to do here is to make sure that we continue to correctly process php engine recoverable errors. Typical example of such error is passing an argument to the function that has different type than typehint. Example function myfunc(stdClass $a) {} myfunc('iamnotaclass'); https://3v4l.org/BWIsO https://3v4l.org/MOJuD In PHP5 this is an error, that is caught by our default_error_handler() and converted to coding_exception. In PHP7 it is NOT an error and never gets to the default_error_handler(), it is a special engine exception that goes straight to our default_exception_handler(). However it does not have type Exception, it has type TypeError which extends Throwable. You need to manually insert the bad code (both normal exception and typeerror) in some places and make sure we process them correctly in the following cases: unittests (it correctly reports failure) behat (it correctly reports failure) delegated transaction (that has to be rolled back on error/exception) install/upgrade code - error/exception terminates the upgrade process and adds an entry to the error log Bonus here is that the errors that were fatal in PHP5 (for example, trying to initiate an instance of non-existing class) become Throwable's in PHP7 and they are caught by the default_exception_handler(). This resolves MDL-46514 for example
    • Affected Branches:
      MOODLE_30_STABLE, MOODLE_31_STABLE
    • Fixed Branches:
      MOODLE_30_STABLE
    • Pull Master Branch:
      MDL-52284-master

      Attachments

        Activity

          People

          • Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Fix Release Date:
              21/Dec/15