From 0eda810d17f70e8278a391e0644de1f7efbbbf01 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Wed, 16 Nov 2016 13:47:40 +0800 Subject: [PATCH] MDL-56459 competency: Invalid use of indirect property key This change ensures that PHP7 and earlier work the same way. Before the patch PHP < 7 would not expand the property as we expected it. More information here: http://php.net/manual/en/migration70.incompatible.php#migration70.incompatible.variable-handling.indirect --- competency/classes/external/exporter.php | 2 +- competency/tests/exporter_test.php | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/competency/classes/external/exporter.php b/competency/classes/external/exporter.php index 1f8f7f72b10..d54c6c6cf8b 100644 --- a/competency/classes/external/exporter.php +++ b/competency/classes/external/exporter.php @@ -158,7 +158,7 @@ abstract class exporter { } else if ($definition['type'] === PARAM_TEXT) { if (!empty($definition['multiple'])) { foreach ($data->$property as $key => $value) { - $data->$property[$key] = external_format_string($value, $context->id); + $data->{$property}[$key] = external_format_string($value, $context->id); } } else { $data->$property = external_format_string($data->$property, $context->id); diff --git a/competency/tests/exporter_test.php b/competency/tests/exporter_test.php index 101e1b46e66..a2d2c90ce9d 100644 --- a/competency/tests/exporter_test.php +++ b/competency/tests/exporter_test.php @@ -111,6 +111,9 @@ class core_competency_exporter_testcase extends advanced_testcase { $output = $PAGE->get_renderer('tool_lp'); $result = $exporter->export($output); + + $this->assertSame('Another string', $result->otherstring); + $this->assertSame(array('String a', 'String b'), $result->otherstrings); } } @@ -130,8 +133,8 @@ class core_competency_testable_exporter extends \core_competency\external\export protected function get_other_values(renderer_base $output) { return array( - 'otherstring' => 'An other string', - 'otherstrings' => array('String a', 'String b') + 'otherstring' => 'Another string', + 'otherstrings' => array('String a', 'String b') ); }