From 47cc73fe1ad25ee4a4e2cb7475ee7bbb39fc743c Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Fri, 1 Sep 2023 09:21:33 +0800 Subject: [PATCH] MDL-72321 question: Ensure that all instance props are defined Since PHP 8.2, all properties on a class must be defined as the PHP Dynamic Property feature has been deprecated. This commit goes one step further and switches this class to using constructor property promotion. This language feature has been available since PHP 8.0 and allows for simplified creation of class properties which are initially defined in the constructor. --- .../output/question_bank_filter_ui.php | 59 +++++-------------- 1 file changed, 15 insertions(+), 44 deletions(-) diff --git a/question/classes/output/question_bank_filter_ui.php b/question/classes/output/question_bank_filter_ui.php index ad6d4fddd2f..409c9162341 100644 --- a/question/classes/output/question_bank_filter_ui.php +++ b/question/classes/output/question_bank_filter_ui.php @@ -30,41 +30,19 @@ use stdClass; */ class question_bank_filter_ui extends datafilter { - /** @var array $searchconditions Searchconditions for the filter. */ - protected $searchconditions = array(); - /** @var int $perpage number of records per page. */ protected $perpage = 0; - /** - * @var string Component for calling the fragment callback. - */ - protected $component; - - /** - * @var string Fragment callback. - */ - protected $callback; - - /** - * @var string View class name. - */ - protected $view; - - /** - * @var int|null if in an activity, the cmid. - */ - protected $cmid; - - /** - * @var array Parameters for the page URL. - */ + /** @var array Parameters for the page URL. */ protected $pagevars; - /** - * @var array Additional parameters used by view classes. - */ - protected $extraparams; + /** @var array $searchconditions Searchconditions for the filter. */ + /** @var array $additionalparams Conditino objects for the current filter. */ + /** @var string $component Component for calling the fragment callback. */ + /** @var string $callback Fragment callback. */ + /** @var string $view View class name. */ + /** @var int|null $cmid if in an activity, the cmid. */ + /** @var array $extraparams Additional parameters used by view classes. */ /** * Create a new datafilter @@ -82,24 +60,17 @@ class question_bank_filter_ui extends datafilter { */ public function __construct( \context $context, - array $searchconditions, - array $additionalparams, - string $component, - string $callback, - string $view, + protected array $searchconditions, + protected array $additionalparams, + protected string $component, + protected string $callback, + protected string $view, ?string $tableregionid = null, - ?int $cmid = null, + protected ?int $cmid = null, array $pagevars = [], - array $extraparams = [] + protected array $extraparams = [] ) { parent::__construct($context, $tableregionid); - $this->searchconditions = $searchconditions; - $this->additionalparams = $additionalparams; - $this->component = $component; - $this->callback = $callback; - $this->view = $view; - $this->cmid = $cmid; - $this->extraparams = $extraparams; if (array_key_exists('sortData', $pagevars)) { foreach ($pagevars['sortData'] as $sortname => $sortorder) { unset($pagevars['sortData'][$sortname]);