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

use static:: for late binding instead of self:: in clean_returnvalue class

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.1
    • Fix Version/s: 3.2
    • Component/s: Web Services
    • Labels:

      Description

      use static:: for late binding instead of self:: in clean_returnvalue class
      I'm wanting to override the clean_returnvalue function tofor my external api class
      I only want to override the external_multiple_structure bit
      It almost works like so:

      class external extends external_api {
          public static function clean_returnvalue(external_description $description, $response) {
              if ($description instanceof external_multiple_structure) {
                  if (!is_array($response)) {
                      throw new invalid_response_exception('Only arrays accepted. The bad value is: \'' .
                                                           print_r($response, true) . '\'');
                  }
                  $result = array();
                  foreach ($response as $key=> $param) {
                      $result[$key] = static::clean_returnvalue($description->content, $param);
                  }
                  return $result;
       
              } else {
                  return parent::clean_returnvalue($description, $response);
              }
          }
      

      But because the parent clean_returnvalue refers to itself with self:: instead of static:: future recursion calls only call the parent class not my extended version.

      Would be great if we could get policy added/changed to use static for late binding always instead of self::

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                berserkk Ben Kelada
                Reporter:
                berserkk Ben Kelada
                Peer reviewer:
                Russell Smith
                Integrator:
                Dan Poltawski
                Tester:
                John Okely
                Participants:
                Component watchers:
                Juan Leyva, Jake Dallimore, Jun Pataleta, Ryan Wyllie
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  5/Dec/16