From 610f4a55b9865cb3e6312153e8f9446f75f248fc Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Tue, 23 Jan 2024 14:45:59 +0000 Subject: [PATCH] MDL-80706 customfield: php8.1 warning about passing null to strlen --- customfield/classes/handler.php | 2 +- customfield/field/text/tests/plugin_test.php | 2 +- customfield/tests/generator/lib.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/customfield/classes/handler.php b/customfield/classes/handler.php index 1a44127854d..df9032b21f6 100644 --- a/customfield/classes/handler.php +++ b/customfield/classes/handler.php @@ -650,7 +650,7 @@ abstract class handler { } $data->instance_form_definition($mform); $field = $data->get_field()->to_record(); - if (strlen($field->description)) { + if (strlen((string)$field->description)) { // Add field description. $context = $this->get_configuration_context(); $value = file_rewrite_pluginfile_urls($field->description, 'pluginfile.php', diff --git a/customfield/field/text/tests/plugin_test.php b/customfield/field/text/tests/plugin_test.php index 9898aee15af..dc686ad0f86 100644 --- a/customfield/field/text/tests/plugin_test.php +++ b/customfield/field/text/tests/plugin_test.php @@ -47,7 +47,7 @@ class plugin_test extends \advanced_testcase { $this->cfields[1] = $this->get_generator()->create_field( ['categoryid' => $this->cfcat->get('id'), 'shortname' => 'myfield1', 'type' => 'text', - 'configdata' => ['maxlength' => 30, 'displaysize' => 50]]); + 'configdata' => ['maxlength' => 30, 'displaysize' => 50], 'description' => null]); $this->cfields[2] = $this->get_generator()->create_field( ['categoryid' => $this->cfcat->get('id'), 'shortname' => 'myfield2', 'type' => 'text', 'configdata' => ['required' => 1, 'maxlength' => 30, 'displaysize' => 50]]); diff --git a/customfield/tests/generator/lib.php b/customfield/tests/generator/lib.php index 06cfe479f97..35815a9e053 100644 --- a/customfield/tests/generator/lib.php +++ b/customfield/tests/generator/lib.php @@ -97,7 +97,7 @@ class core_customfield_generator extends component_generator_base { if (!isset($record->shortname)) { $record->shortname = "fld$i"; } - if (!isset($record->description)) { + if (!property_exists($record, 'description')) { $record->description = "Field $i description"; } if (!isset($record->descriptionformat)) {