davidherney / moodle-format_onetopic

Course format Onetopic to LMS Moodle
GNU General Public License v3.0
19 stars 44 forks source link

PHP 7.2 warning "Parameter must be an array" #54

Closed lninic closed 5 years ago

lninic commented 5 years ago

Moodle version: Moodle 3.5.2+ (Build: 20180914) PHP version : PHP 7.2.11 Onetopic version: san juan 2018010604

This warning appears when editing course above tabs: Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/moodle/course/format/onetopic/renderer.php on line 395

This is the 395 line:


      if (!$course->hidetabsbar && count($tabs[0]) > 0) {

            if ($PAGE->user_is_editing() && has_capability('moodle/course:update', $context)) {

                // Increase number of sections.
                $straddsection = get_string('increasesections', 'moodle');
                $url = new moodle_url('/course/changenumsections.php',
                    array('courseid' => $course->id,
                        'increase' => true,
                        'sesskey' => sesskey(),
                        'insertsection' => 0));
                $icon = $this->output->pix_icon('t/switch_plus', $straddsection);
                $tabs[] = new tabobject("tab_topic_add", $url, $icon, s($straddsection));

            }

It seem count($tabs) is not an array so the latest PHP 7.2 shows a warning there, please check the changes here: http://php.net/manual/en/migration72.incompatible.php http://php.net/manual/en/function.count.php#refsect1-function.count-changelog

Is there any way to fix this error?

stephanepoinsart commented 5 years ago

I noticed the same, I don't know if the fix is right (I don't use nested tabs or anything fancy) but i just removed the [0] :

diff --git a/renderer.php b/renderer.php
index 6a5e631..854dde8 100644
--- a/renderer.php
+++ b/renderer.php
@@ -392,7 +392,7 @@ class format_onetopic_renderer extends format_section_renderer_base {
         $sectionnavlinks = $this->get_nav_links($course, $sections, $displaysection);
         $sectiontitle = '';

-        if (!$course->hidetabsbar && count($tabs[0]) > 0) {
+        if (!$course->hidetabsbar && $tabs && count($tabs) > 0) {

             if ($PAGE->user_is_editing() && has_capability('moodle/course:update', $context)) {
davidherney commented 5 years ago

Yes... the solution is very simple. I fix it in branch "MOODLE_33_select_visible_tab_by_default ", into the commit: https://github.com/davidherney/moodle-format_onetopic/commit/f9d3857f485c73f0342b1393a55dd7bd74a8fd79

I waiting for testers in order to merge it with the master branch.