moodle-cs icon indicating copy to clipboard operation
moodle-cs copied to clipboard

magic __construct() in anonymous class cause error

Open PawelSuwinski opened this issue 5 years ago • 0 comments

Hi

Is usage of magic __construct() in derived classes restricted by policy?

Code:

# auth/emailotp/settings.php
#(...)
    $settings->add(new class(
        'auth_emailotp/minrequestperiod',
        get_string('minrequestperiod', 'auth_emailotp'),
        get_string('minrequestperiod_help', 'auth_emailotp')
    ) extends admin_setting_configtext {
        public function __construct($name, $visiblename, $description) {
            $logreader = reset(get_log_manager()->get_readers('\core\log\sql_reader'));
            parent::__construct($name, $visiblename, $description, $logreader ? 120 : 0, PARAM_INT);
            if (!$logreader && !empty($this->get_setting())) {
                $this->description .= ' '.get_string('logstorerequired', 'auth_emailotp',
                    (string)new moodle_url('/admin/settings.php', ['section' => 'managelogging'])
                );
            }
        }
    });

gives codechecker error:

moodlehq/moodle-local_codechecker#67: ········public·function·__construct($name,·$visiblename,·$description)·{
Function name "__construct" is invalid; only PHP magic methods should be prefixed with a double underscore

version: 2020100200

PawelSuwinski avatar Nov 18 '20 14:11 PawelSuwinski