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

Make Moodle code compatible with Exception/Throwable changes in PHP7

    XMLWordPrintable

Details

    • Task
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.0, 3.1
    • 3.0.1
    • General
    • MOODLE_30_STABLE, MOODLE_31_STABLE
    • MOODLE_30_STABLE
    • MDL-52284-master
    • 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

    Attachments

      Activity

        People

          tlevi Tony Levi
          marina Marina Glancy
          Dan Poltawski Dan Poltawski
          Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
          Jun Pataleta Jun Pataleta
          Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias, Sujith Haridasan
          Votes:
          0 Vote for this issue
          Watchers:
          6 Start watching this issue

          Dates

            Created:
            Updated:
            Resolved:
            21/Dec/15