Skip to content

Commit

Permalink
MDL-60281 general: various strict corrections for PHP7.2
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
marinaglancy committed Oct 16, 2017
1 parent d28eb51 commit 78da366
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions backup/util/structure/base_nested_element.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ public function add_final_elements($final_elements) {
}

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);
Expand Down
3 changes: 2 additions & 1 deletion cache/disabledlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@ public function delete_many(array $keys, $recurse = true) {
* 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;
}

Expand Down
1 change: 1 addition & 0 deletions filter/urltolink/filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ protected function convert_urls_into_links(&$text) {
//<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.
Expand Down
2 changes: 1 addition & 1 deletion lib/navigationlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ public function action() {
* @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.
Expand Down
2 changes: 1 addition & 1 deletion lib/outputcomponents.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/phpunit/classes/base_testcase.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static function assertTag($matcher, $actual, $message = '', $ishtml = tru
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);
}

Expand Down
2 changes: 1 addition & 1 deletion user/tests/userlib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -887,8 +887,8 @@ public function test_user_get_participants() {
// 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));
}

/**
Expand Down

0 comments on commit 78da366

Please sign in to comment.