WildcardSearch / Advanced-Sidebox

A plugin for MyBB forums that displays custom boxes on various forum pages.
GNU General Public License v3.0
20 stars 10 forks source link

Warning's when no sideboxes present #2

Closed avril-gh closed 11 years ago

avril-gh commented 11 years ago

MyBB 1.6.9 / PHP 5.4.10

when there are no sideboxes present in 'manage sideboxes' tab, (for example - just after installing plugin) following warnings occur in website front page

Warning [2] Invalid argument supplied for foreach() - Line: 99 - File: inc/plugins/adv_sidebox.php PHP 5.4.10 (Linux)

/inc/plugins/adv_sidebox.php 99 errorHandler->error /inc/class_plugins.php 101 adv_sidebox_start /index.php 25 pluginSystem->run_hooks

Ofcourse warnings can be hidden but it would be better to fix it now while there are still no other issues, than fight it later when many new warnings would accumulate on stack.

WildcardSearch commented 11 years ago

I can't reproduce that error. Are you using the latest version?

WildcardSearch commented 11 years ago

Try that update and see if it solves your problem. :+1:

avril-gh commented 11 years ago

Are you using the latest version?

Advanced Sidebox (1.2) (at php 5.4.10)

I can't reproduce that error.

Some servers may be configured to hide errors and warnings. Try enabling error_reporting for test before foreach in line 90.

error_reporting(E_ALL ^ E_NOTICE);
foreach($sideboxes as $this_box)

Check for non array result from adv_sidebox_get_all_sideboxes() before foreach loop

Yes, when there are no sideboxes published then $sideboxes is empty and cause warnings. Theres many ways to fix it. Personally i added (array) in line 90. Seems everything working ok now and not cause warnings when theres no sideboxes.

    foreach((array)$sideboxes as $this_box)

Fixed. Thanks

(btw - your plugin is awesome, i love how freely it can be customised and that practically anything can be put to sideboxes. Excellent. Keep up good work)

WildcardSearch commented 11 years ago

Thanks for your kind words.

I can't cast the return of adv_sidebox_get_all_sideboxes() as an array because non-array is meant to signify no sideboxes. I just forgot to check.

Added a check that exits the function if the return is non-array. :)

Cheers.