Invalid parameter in core_get_string call

Re: Invalid parameter in core_get_string call

by David Balme -
Number of replies: 0

I discovered this issue as well.

The problem is a mismatch between the external function parameters returned by get_string_parameters() and the actual method signature of get_string:  get_string does not have a lang parameter.  However the definition below specifies one (see below).

    public static function get_string_parameters() {
        return new external_function_parameters(
            array('stringid' => new external_value(PARAM_STRINGID, 'string identifier'),
                  'component' => new external_value(PARAM_COMPONENT,'component', VALUE_DEFAULT, 'moodle'),
                  'lang' => new external_value(PARAM_LANG, 'lang', VALUE_DEFAULT, null),
                  'stringparams' => new external_multiple_structure (
                      new external_single_structure(array(
                          'name' => new external_value(PARAM_ALPHANUMEXT, 'param name
                            - if the string expect only one $a parameter then don\'t send this field, just send the value.', VALUE_OPTIONAL),
                          'value' => new external_value(PARAM_TEXT,'param value'))),
                          'the definition of a string param (i.e. {$a->name})', VALUE_DEFAULT, array()
                   )
            )
        );
    }

I will do as Bill suggested, ie comment out the 'lang' parameter definition from the get_string web service call.  However that only addresses this issue temporarily ( and only for me .. and Bill smile ).

Has this been resolved in a later version of Moodle?  I too am using version 2.6.

I'm not a PHP developer (I spend most of my time in java) and I'm more used to stronger typed languages and so not at all used to this type of scenario.  Nonetheless I have a suggestion that could help guard against this parameter/mismatch and create a more tightly checked system.

Is it possible to write a unit (or integration) test that iterates through all the externally defined functions (SELECT * FROM mdl_external_functions) and validates that all the function parameter definitions actually match up with the function signatures.  Not being a PHP dev I'm not sure if you can extract that sort of meta data.  Anyhow, just a thought.  No idea if this is doable.  smile