[Moodle Edash] Fix Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Table of Contents

[Moodle Edash] Fix Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Err info

Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated... theme/edash/renderers/course-renderer.php on line 53

Fix Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Origin Function

protected function coursecat_category(coursecat_helper $chelper, $coursecat, $depth) {

        global $CFG, $PAGE;

        $categoryname = $coursecat->get_formatted_name();
        $edash_category_link = new moodle_url('/course/index.php', array('categoryid' => $coursecat->id));

        $edash_cat = $coursecat->id;
        $edash_cat_summary_unclean = $chelper->get_category_formatted_description($coursecat);
        $edash_cat_summary = preg_replace("/<img[^>]+\>/i", " ", $edash_cat_summary_unclean);

        $children_courses = $coursecat->get_courses();
        $edash_items_count = '';

        if ($coursecat->get_children_count() > 0) {
            $edash_items_count .= $coursecat->get_children_count() . ' ' . get_string('categories');
        } else {
            $edash_items_count .= count($coursecat->get_courses()) . ' ' . get_string('courses');
        }
        $edash_cat_updated = get_string('modified') . ' ' . userdate($coursecat->timemodified, '%d %B %Y', 0);
        ..............

Change $edash_cat_summary from

 $edash_cat_summary = preg_replace("/<img[^>]+\>/i", " ", $edash_cat_summary_unclean);

to

$edash_cat_summary = $edash_cat_summary_unclean ? preg_replace("/<img[^>]+\>/i", " ", $edash_cat_summary_unclean): "";

References

https://www.grepper.com/answers/496951/str_replace%28%29%3A+Passing+null+to+parameter+%233+%28%24subject%29+of+type+array%7Cstring+is+deprecated+Filename%3A+core%2FOutput.php

Leave a Reply

Your email address will not be published. Required fields are marked *