{"record":{"id":"6355fcf2ae1de804","repo":"moodle/moodle","slug":"mustbeoveride","errorCode":"mustbeoveride","errorMessage":"mustbeoveride","messagePattern":"mustbeoveride","errorType":"exception","errorClass":"moodle_exception","httpStatus":null,"severity":"error","filePath":"public/user/filters/lib.php","lineNumber":323,"sourceCode":"    /**\n     * Constructor\n     * @param string $name the name of the filter instance\n     * @param string $label the label of the filter instance\n     * @param boolean $advanced advanced form element flag\n     */\n    public function __construct($name, $label, $advanced) {\n        $this->_name     = $name;\n        $this->_label    = $label;\n        $this->_advanced = $advanced;\n    }\n\n    /**\n     * Returns the condition to be used with SQL where\n     * @param array $data filter settings\n     * @return string the filtering condition or null if the filter is disabled\n     */\n    public function get_sql_filter($data) {\n        throw new \\moodle_exception('mustbeoveride', 'debug', '', 'get_sql_filter');\n    }\n\n    /**\n     * Retrieves data from the form data\n     * @param stdClass $formdata data submited with the form\n     * @return mixed array filter data or false when filter not set\n     */\n    public function check_data($formdata) {\n        throw new \\moodle_exception('mustbeoveride', 'debug', '', 'check_data');\n    }\n\n    /**\n     * Adds controls specific to this filter in the form.\n     * @param moodleform $mform a MoodleForm object to setup\n     */\n    public function setupForm(&$mform) {\n        throw new \\moodle_exception('mustbeoveride', 'debug', '', 'setupForm');\n    }","sourceCodeStart":305,"sourceCodeEnd":341,"githubUrl":"https://github.com/moodle/moodle/blob/48ea8c33227277e916cdd4079dbecef448b37f2c/public/user/filters/lib.php#L305-L341","documentation":"This is a Moodle abstract-base-class guard. filter_object (public/user/filters/lib.php) declares get_sql_filter() as a method every concrete filter type must override; the base implementation does nothing but throw \\moodle_exception('mustbeoveride','debug','','get_sql_filter'). It fires when code calls get_sql_filter() on a filter subclass that never implemented it, i.e. an unimplemented abstract method, not a runtime data problem.","triggerScenarios":"Calling get_sql_filter($data) on an instance of a class extending the base filter class in user/filters/lib.php that has not overridden get_sql_filter() — typically a custom or third-party user filter with an incomplete implementation, or the base class instantiated directly.","commonSituations":"Writing a new custom user filter and forgetting to implement get_sql_filter() while implementing the other required methods; upgrading Moodle so a previously working subclass no longer matches the API contract; instantiating the abstract base filter_type directly instead of a concrete subclass.","solutions":["Implement get_sql_filter($data) in the concrete filter subclass, returning the SQL WHERE condition string (or null if the filter is disabled).","Check that you are instantiating the intended concrete filter subclass, not the abstract base class from lib.php.","Compare your subclass against a core filter (e.g. user/filters/text.php or checkbox.php) and implement every method the base class marks as must-be-overridden.","If the exception names 'get_sql_filter' but you did override it, verify there is no signature/visibility mismatch (e.g. protected vs public, wrong parameter list) that silently skips the override."],"exampleFix":"// before\nclass my_custom_filter extends filter_type {\n    public function setupForm(&$mform) { /* ... */ }\n    // get_sql_filter() never implemented -> base class throws mustbeoveride\n}\n\n// after\nclass my_custom_filter extends filter_type {\n    public function setupForm(&$mform) { /* ... */ }\n    public function get_sql_filter($data) {\n        if (empty($data['value'])) {\n            return null; // filter disabled\n        }\n        return 'fieldname = ' . $data['value'];\n    }\n}","handlingStrategy":"type-guard","validationCode":"// Before using a filter instance, ensure all required overrides exist:\nif (!method_exists($filter, 'get_sql_filter')) {\n    throw new coding_exception('Filter class ' . get_class($filter) . ' must override get_sql_filter()');\n}","typeGuard":"// PHP guard for a properly implemented filter subclass\nfunction is_implemented_filter($filter): bool {\n    return $filter instanceof filter_type\n        && (new ReflectionMethod($filter, 'get_sql_filter'))->getDeclaringClass()->getName() !== 'filter_type';\n}","tryCatchPattern":"try {\n    $condition = $filter->get_sql_filter($data);\n} catch (\\moodle_exception $e) {\n    if ($e->errorcode === 'mustbeoveride') {\n        debugging('Filter subclass missing get_sql_filter override: ' . get_class($filter), DEBUG_DEVELOPER);\n        $condition = null; // treat filter as disabled\n    } else {\n        throw $e;\n    }\n}","preventionTips":["Always implement all four mandatory methods (get_sql_filter, check_data, setupForm, get_label) when creating a filter subclass.","Derive new filters from a core concrete filter or copy its full method set.","Add a unit test that instantiates each filter subclass and asserts none of the base methods throw mustbeoveride.","Run Reflection checks in dev to catch base-class-only implementations early."],"tags":["php","moodle","abstract-method","filter"],"backgroundTag":"abstract-method-not-implemented","analyzedSha":"48ea8c33227277e916cdd4079dbecef448b37f2c","analyzedAt":"2026-09-14T20:34:48.527Z","contentChangedAt":"2026-09-14T20:34:48.527Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}