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
This commit is contained in:
Marina Glancy
2017-10-16 09:37:20 +08:00
parent d28eb51ddc
commit 78da366b56
7 changed files with 9 additions and 7 deletions
@@ -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);
+2 -1
View File
@@ -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;
}
+1
View File
@@ -75,6 +75,7 @@ class filter_urltolink extends moodle_text_filter {
//<a href="blah">
$filterignoretagsopen = array('<a\s[^>]+?>', '<span[^>]+?class="nolink"[^>]*?>');
$filterignoretagsclose = array('</a>', '</span>');
$ignoretags = [];
filter_save_ignore_tags($text,$filterignoretagsopen,$filterignoretagsclose,$ignoretags);
// Check if we support unicode modifiers in regular expressions. Cache it.
+1 -1
View File
@@ -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.
+1 -1
View File
@@ -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.
+1 -1
View File
@@ -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);
}
+1 -1
View File
@@ -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));
}
/**