Skip to content

Commit

Permalink
MDL-76356 various: avoid implicit conversion to arrays
Browse files Browse the repository at this point in the history
PHP before version 8.1 automatically converted stdClass or 'false' to arrays if
function parameter expects array (for example, "reset").
PHP 8.1 shows notices in these situations
  • Loading branch information
marinaglancy authored and stronk7 committed Jan 10, 2023
1 parent b8b905c commit 594a8c5
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion admin/roles/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function test_export_user_data() {
$writer = writer::with_context($context);
$this->assertTrue($writer->has_any_data());
if ($context->contextlevel == CONTEXT_MODULE) {
if ($data = $writer->get_data($subcontextstudent)) {
if ($data = (array)$writer->get_data($subcontextstudent)) {
$this->assertEquals($user->id, reset($data)->userid);
}
if ($data = (array)$writer->get_data($subcontextrc)) {
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/policy/classes/output/page_agreedocs.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ protected function redirect_to_policies($userid, $returnurl = null) {
$cache = \cache::make('core', 'presignup');
$cachekey = 'tool_policy_viewedpolicies';

$viewedpolicies = $cache->get($cachekey);
$viewedpolicies = $cache->get($cachekey) ?: [];
if (!empty($viewedpolicies)) {
// Get the list of the policies docs which the user haven't viewed during this session.
$pendingpolicies = array_diff($currentpolicyversionids, $viewedpolicies);
Expand Down
2 changes: 1 addition & 1 deletion analytics/classes/calculation_info.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function save(\core_analytics\calculable $calculable, \core_analytics\loc
$samplekey = self::get_sample_key($uniquesampleid);

// Update the cached data adding the new indicator data.
$cacheddata = $cache->get($samplekey);
$cacheddata = $cache->get($samplekey) ?: [];
$cacheddata[$calculableclass] = $infokeys;
$cache->set($samplekey, $cacheddata);
}
Expand Down
2 changes: 2 additions & 0 deletions h5p/tests/helper_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,9 @@ public function test_get_messages(): void {
$this->assertTrue(empty($messages->info));

// Add an some messages manually and check they are still there.
$messages->error = [];
$messages->error['error1'] = 'Testing ERROR message';
$messages->info = [];
$messages->info['info1'] = 'Testing INFO message';
$messages->info['info2'] = 'Testing INFO message';
helper::get_messages($messages, $factory);
Expand Down
2 changes: 1 addition & 1 deletion lib/completionlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ public function get_data($cm, $wholecourse = false, $userid = 0, $unused = null)
if (!isset($this->course->cacherev)) {
$this->course = get_course($this->course_id);
}
if ($cacheddata = $completioncache->get($key)) {
if ($cacheddata = ($completioncache->get($key) ?: [])) {
if ($cacheddata['cacherev'] != $this->course->cacherev) {
// Course structure has been changed since the last caching, forget the cache.
$cacheddata = array();
Expand Down

0 comments on commit 594a8c5

Please sign in to comment.