From 78da366b560f284eab0ded2f63cece4870cf37e5 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Mon, 2 Oct 2017 09:19:39 +0800 Subject: [PATCH] MDL-60281 general: various strict corrections for PHP7.2 - count() can only be called on arrays or Countable, it can not be called on null - recordset is neither so iterator_count() should be used - instanceof or get_class() can not be applied to non-objects - class methods must have the same arguments as methods in parent class --- backup/util/structure/base_nested_element.class.php | 4 ++-- cache/disabledlib.php | 3 ++- filter/urltolink/filter.php | 1 + lib/navigationlib.php | 2 +- lib/outputcomponents.php | 2 +- lib/phpunit/classes/base_testcase.php | 2 +- user/tests/userlib_test.php | 2 +- 7 files changed, 9 insertions(+), 7 deletions(-) diff --git a/backup/util/structure/base_nested_element.class.php b/backup/util/structure/base_nested_element.class.php index b48defc8235..0067410a210 100644 --- a/backup/util/structure/base_nested_element.class.php +++ b/backup/util/structure/base_nested_element.class.php @@ -164,8 +164,8 @@ abstract class base_nested_element extends base_final_element { } public function add_child($element) { - if (!($element instanceof base_nested_element)) { // parameter must be a base_nested_element - if (!$found = get_class($element)) { + if (!is_object($element) || !($element instanceof base_nested_element)) { // parameter must be a base_nested_element + if (!is_object($element) || !($found = get_class($element))) { $found = 'non object'; } throw new base_element_struct_exception('nestedelementincorrect', $found); diff --git a/cache/disabledlib.php b/cache/disabledlib.php index 3a83d1fd643..2bcc1caf8ad 100644 --- a/cache/disabledlib.php +++ b/cache/disabledlib.php @@ -125,9 +125,10 @@ class cache_disabled extends cache { * Checks if the cache has the requested key. * * @param int|string $key Unused. + * @param bool $tryloadifpossible Unused. * @return bool */ - public function has($key) { + public function has($key, $tryloadifpossible = false) { return false; } diff --git a/filter/urltolink/filter.php b/filter/urltolink/filter.php index 211e149e837..b8a333e2952 100644 --- a/filter/urltolink/filter.php +++ b/filter/urltolink/filter.php @@ -75,6 +75,7 @@ class filter_urltolink extends moodle_text_filter { //<a href="blah"> $filterignoretagsopen = array(']+?>', ']+?class="nolink"[^>]*?>'); $filterignoretagsclose = array('', ''); + $ignoretags = []; filter_save_ignore_tags($text,$filterignoretagsopen,$filterignoretagsclose,$ignoretags); // Check if we support unicode modifiers in regular expressions. Cache it. diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 280b1191be8..efb92a95513 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -843,7 +843,7 @@ class navigation_node implements renderable { * @copyright 2010 Sam Hemelryk * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class navigation_node_collection implements IteratorAggregate { +class navigation_node_collection implements IteratorAggregate, Countable { /** * A multidimensional array to where the first key is the type and the second * key is the nodes key. diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index e237ba5a9aa..fac5c37ab8e 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -2640,7 +2640,7 @@ class html_table { * $row2->cells = array($cell2, $cell3); * $t->data = array($row1, $row2); */ - public $data; + public $data = []; /** * @deprecated since Moodle 2.0. Styling should be in the CSS. diff --git a/lib/phpunit/classes/base_testcase.php b/lib/phpunit/classes/base_testcase.php index 231ce1f4198..54eb63fa7ed 100644 --- a/lib/phpunit/classes/base_testcase.php +++ b/lib/phpunit/classes/base_testcase.php @@ -73,7 +73,7 @@ abstract class base_testcase extends PHPUnit_Framework_TestCase { public static function assertNotTag($matcher, $actual, $message = '', $ishtml = true) { $dom = PHPUnit_Util_XML::load($actual, $ishtml); $tags = self::findNodes($dom, $matcher, $ishtml); - $matched = count($tags) > 0 && $tags[0] instanceof DOMNode; + $matched = (is_array($tags) && count($tags) > 0) && $tags[0] instanceof DOMNode; self::assertFalse($matched, $message); } diff --git a/user/tests/userlib_test.php b/user/tests/userlib_test.php index a5a68620db3..0168929fcc2 100644 --- a/user/tests/userlib_test.php +++ b/user/tests/userlib_test.php @@ -887,8 +887,8 @@ class core_userliblib_testcase extends advanced_testcase { // the group and has the name 'searchforthis' and has also accessed the course in the last day. $userset = user_get_participants($course->id, $group->id, $accesssince + 1, $roleids['student'], 0, -1, 'searchforthis'); - $this->assertEquals(1, sizeof($userset)); $this->assertEquals($student1->id, $userset->current()->id); + $this->assertEquals(1, iterator_count($userset)); } /**