Skip to content

Commit b9ccbef

Browse files
committed
Fix count() notices on PHP 7.2
Fixes #540
1 parent 8494377 commit b9ccbef

4 files changed

Lines changed: 14 additions & 9 deletions

File tree

qa-include/app/page.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ function qa_set_template($template)
464464
* @param array $categoryids
465465
* @return array
466466
*/
467-
function qa_content_prepare($voting = false, $categoryids = null)
467+
function qa_content_prepare($voting = false, $categoryids = array())
468468
{
469469
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
470470

@@ -480,10 +480,12 @@ function qa_content_prepare($voting = false, $categoryids = null)
480480
$navpages = qa_db_get_pending_result('navpages');
481481
$widgets = qa_db_get_pending_result('widgets');
482482

483-
if (isset($categoryids) && !is_array($categoryids)) // accept old-style parameter
483+
if (!is_array($categoryids)) {
484+
// accept old-style parameter
484485
$categoryids = array($categoryids);
486+
}
485487

486-
$lastcategoryid = count($categoryids) ? end($categoryids) : null;
488+
$lastcategoryid = count($categoryids) > 0 ? end($categoryids) : null;
487489
$charset = 'utf-8';
488490
$language = qa_opt('site_language');
489491
$language = empty($language) ? 'en' : qa_html($language);

qa-include/pages/hot.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
$countslugs ? $categories[$categoryid]['qcount'] : qa_opt('cache_qcount'), // total count
6666
$sometitle, // title if some questions
6767
$nonetitle, // title if no questions
68-
QA_ALLOW_UNINDEXED_QUERIES ? $categories : null, // categories for navigation
68+
QA_ALLOW_UNINDEXED_QUERIES ? $categories : array(), // categories for navigation
6969
$categoryid, // selected category id
7070
true, // show question counts in category navigation
7171
QA_ALLOW_UNINDEXED_QUERIES ? 'hot/' : null, // prefix for links in category navigation (null if no navigation)

qa-include/pages/unanswered.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
@$count, // total count
123123
$sometitle, // title if some questions
124124
$nonetitle, // title if no questions
125-
QA_ALLOW_UNINDEXED_QUERIES ? $categories : null, // categories for navigation (null if not shown on this page)
125+
QA_ALLOW_UNINDEXED_QUERIES ? $categories : array(), // categories for navigation (null if not shown on this page)
126126
QA_ALLOW_UNINDEXED_QUERIES ? $categoryid : null, // selected category id (null if not relevant)
127127
false, // show question counts in category navigation
128128
QA_ALLOW_UNINDEXED_QUERIES ? 'unanswered/' : null, // prefix for links in category navigation (null if no navigation)

qa-include/qa-theme-base.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,11 @@ public function reorder_parts($parts, $beforekey = null, $reorderrelative = true
208208
*/
209209
public function widgets($region, $place)
210210
{
211-
if (count(@$this->content['widgets'][$region][$place])) {
211+
$widgetsHere = isset($this->content['widgets'][$region][$place]) ? $this->content['widgets'][$region][$place] : array();
212+
if (is_array($widgetsHere) && count($widgetsHere) > 0) {
212213
$this->output('<div class="qa-widgets-' . $region . ' qa-widgets-' . $region . '-' . $place . '">');
213214

214-
foreach ($this->content['widgets'][$region][$place] as $module) {
215+
foreach ($widgetsHere as $module) {
215216
$this->output('<div class="qa-widget-' . $region . ' qa-widget-' . $region . '-' . $place . '">');
216217
$module->output_widget($region, $place, $this, $this->template, $this->request, $this->content);
217218
$this->output('</div>');
@@ -629,8 +630,10 @@ public function nav_item($key, $navlink, $class, $level = null)
629630
(@$navlink['state'] ? (' qa-' . $class . '-' . $navlink['state']) : '') . ' qa-' . $class . '-' . $suffix . '">');
630631
$this->nav_link($navlink, $class);
631632

632-
if (count(@$navlink['subnav']))
633-
$this->nav_list($navlink['subnav'], $class, 1 + $level);
633+
$subnav = isset($navlink['subnav']) ? $navlink['subnav'] : array();
634+
if (is_array($subnav) && count($subnav) > 0) {
635+
$this->nav_list($subnav, $class, 1 + $level);
636+
}
634637

635638
$this->output('</li>');
636639
}

0 commit comments

Comments
 (0)