Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warnings in PHP 8 in Admin CP #136

Open
Rhababo opened this issue Oct 26, 2023 · 0 comments
Open

Warnings in PHP 8 in Admin CP #136

Rhababo opened this issue Oct 26, 2023 · 0 comments
Labels

Comments

@Rhababo
Copy link

Rhababo commented Oct 26, 2023

Describe the bug
When setting up the form, this warning is thrown:

On the "View Form" Tab:

  1. Warning [2] Undefined array key "page" - Line: 993 - File: admin/modules/config/formcreator.php PHP 8.1.16 (Linux)

On the "Create Form" Tab, Prior to the "Create a New Form" block:

  1. Warning [2] Trying to access array offset on value of type null - Line: 146 - File: admin/modules/config/formcreator.php PHP 8.1.16 (Linux)
  2. Warning [2] Trying to access array offset on value of type null - Line: 153 - File: admin/modules/config/formcreator.php PHP 8.1.16 (Linux)
  3. Warning [2] Trying to access array offset on value of type null - Line: 160 - File: admin/modules/config/formcreator.php PHP 8.1.16 (Linux)
  4. Warning [2] Trying to access array offset on value of type null - Line: 168 - File: admin/modules/config/formcreator.php PHP 8.1.16 (Linux)
  5. Warning [2] Trying to access array offset on value of type null - Line: 169 - File: admin/modules/config/formcreator.php PHP 8.1.16 (Linux)
  6. Warning [2] Trying to access array offset on value of type null - Line: 170 - File: admin/modules/config/formcreator.php PHP 8.1.16 (Linux)

On the "Create Form" Tab, After the "Create a New Form" block:

  1. Warning [2] Trying to access array offset on value of type null - Line: 177 - File: admin/modules/config/formcreator.php PHP 8.1.16 (Linux)
  2. Warning [2] Trying to access array offset on value of type null - Line: 180 - File: admin/modules/config/formcreator.php PHP 8.1.16 (Linux)
  3. Warning [2] Trying to access array offset on value of type null - Line: 201 - File: admin/modules/config/formcreator.php PHP 8.1.16 (Linux)
  4. Warning [2] Trying to access array offset on value of type null - Line: 206 - File: admin/modules/config/formcreator.php PHP 8.1.16 (Linux)
  5. Warning [2] Trying to access array offset on value of type null - Line: 213 - File: admin/modules/config/formcreator.php PHP 8.1.16 (Linux)
  6. Warning [2] Trying to access array offset on value of type null - Line: 217 - File: admin/modules/config/formcreator.php PHP 8.1.16 (Linux)
  7. Warning [2] Undefined array key "posticon" - Line: 225 - File: admin/modules/config/formcreator.php PHP 8.1.16 (Linux)
  8. Warning [2] Undefined variable $theme - Line: 243 - File: admin/modules/config/formcreator.php PHP 8.1.16 (Linux)
  9. Warning [2] Trying to access array offset on value of type null - Line: 243 - File: admin/modules/config/formcreator.php PHP 8.1.16 (Linux)
  10. Warning [2] Trying to access array offset on value of type null - Line: 246 - File: admin/modules/config/formcreator.php PHP 8.1.16 (Linux)
    (The above 3 warnings are repeated multiple times)
  11. Warning [2] Trying to access array offset on value of type null - Line: 264 - File: admin/modules/config/formcreator.php PHP 8.1.16 (Linux)
  12. Warning [2] Trying to access array offset on value of type null - Line: 268 - File: admin/modules/config/formcreator.php PHP 8.1.16 (Linux)
  13. Warning [2] Trying to access array offset on value of type null - Line: 270 - File: admin/modules/config/formcreator.php PHP 8.1.16 (Linux)

After the "Process Options" block

  1. Warning [2] Trying to access array offset on value of type null - Line: 294 - File: admin/modules/config/formcreator.php PHP 8.1.16 (Linux)
  2. Warning [2] Undefined property: MyLanguage::$fc_lang_width_desc - Line: 296 - File: admin/modules/config/formcreator.php PHP 8.1.16 (Linux)
  3. Warning [2] Trying to access array offset on value of type null - Line: 297 - File: admin/modules/config/formcreator.php PHP 8.1.16 (Linux)

(Note that some of the later line numbers won't line up as I was debugging the code, but in general they occurred whenever $formcreator->setting['somevalue'] appears)

To Reproduce
Steps to reproduce the behavior:

  1. Go to Configuration -> Form Creator
  2. See error

Expected behavior
No PHP warning. These don't impact the functionality, the warnings are largely annoying and make error logging tedious.

Desktop (please complete the following information):

  • MyBB version: 1.8.36
  • Plugin version: 2.6.6
  • PHP version: 8.1.16
  • MySQL version: 5.7

Possible fix(s):
Warning 1:
I changed the line in question from:
if ($mybb->input['page']) {
to
if (isset($mybb->input['page'])) {
and that seemed to resolve the warning.

Warning 2-4:
I replaced the set code for the allowed gid types with:

  $radioboxes = "";

   $option_gidtypeAll = array();
   $option_gidtypeSelected = array();
   $option_gidtypeUnselected = array();
    if(isset($form_container->settings['allowedgidtype'])){
        switch($form_container->settings['allowedgidtype']){
            case -1:
                $option_gidtypeAll[] =["checked" => 1];
                break;
            case 0:
                $option_gidtypeSelected[] = ["checked" => 1];
                break;
            case 1:
                $option_gidtypeUnselected[] = ["checked" => 1];
                break;
            default:
                break;
        }
    } else {
        //set default radio button for when 'allowedgidtype' is not set
        $option_gidtypeSelected[] = ["checked" => 1];
    }
    $radioboxes .= $form->generate_radio_button("settings[allowedgidtype]", -1, $lang->fc_allow_all_groups, $option_gidtypeAll) . "<br />";
    $radioboxes .= $form->generate_radio_button("settings[allowedgidtype]", 0, $lang->fc_allow_selected_groups, $option_gidtypeSelected) . "<br />";
    $radioboxes .= $form->generate_radio_button("settings[allowedgidtype]", 1, $lang->fc_allow_unselected_groups, $option_gidtypeUnselected);

Warning 5-7
I replaced the following lines:

 //check if set for PHP 8 compatibility, set to default if not
    $allowedgidvalue = isset($formcreator->settings['allowedgid']) ? $formcreator->settings['allowedgid'] : array();
    $customdeniedvalue = isset($formcreator->settings['customdenied']) ? $formcreator->settings['customdenied'] : "";
    $limitusagevalue = isset($formcreator->settings['limitusage']) ? $formcreator->settings['limitusage'] : "";

    $form_container->output_row($lang->fc_allowed_groups." <em>*</em>", $lang->fc_allowed_groups_desc, $radioboxes . "<br /><br />" . $form->
        generate_group_select("settings[allowedgid][]", $allowedgidvalue, array("multiple" => true)));
    $form_container->output_row($lang->fc_custom_denied_message, $lang->fc_custom_denied_message_desc, $form->generate_text_area("settings[customdenied]", $customdeniedvalue));
    $form_container->output_row($lang->fc_limitusage, $lang->fc_limitusage_desc, $form->generate_numeric_field("settings[limitusage]", $limitusagevalue));
    $form_container->output_row($lang->fc_status." <em>*</em>", $lang->fc_status_desc, $form->generate_yes_no_radio("active", $formcreator->active));
    $form_container->end();

The other warnings can be removed using a similar method to above except for:

Warning 15 and 16 can be removed by checking if in the admin cp (as the $theme variable doesn't exist in admin cp)
$dbicon['path'] = str_replace("{theme}", $theme['imgdir'], $dbicon['path']);
becomes
$dbicon['path'] = !defined('IN_ADMINCP') ? str_replace("{theme}", $theme['imgdir'], $dbicon['path']) : $dbicon['path'];

Warning 22 is due to a typo where $lang->fc_lang_width_desc, should be $lang->fc_label_width_desc,

I haven't done many tests with these, but I could create a pull request with my changes if you'd like.

@Rhababo Rhababo added the bug label Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant