E_NOTICE: Trying to access array offset on value of type null?

8 posts by 2 authors in: Forums > CMS Builder
Last Post: September 21   (RSS)

By gkornbluth - September 20 - edited: September 20

Good morning All,

I'm running CMSB version 3.56 with PHP 7.4 and I'm getting the following error every time I access the record list for  sections called  e_blast_general or the section called e_blast_press_release:

E_NOTICE: Trying to access array offset on value of type null
/home3/mrqsygmy/public_html/cmsAdmin/lib/menus/default/list.php (line 129)
https://dbtproviders.com/cmsAdmin/admin.php?menu=e_blast_general

and an identical error for lines 115 and 131.

I got the same errors in Version 3.55 and thought the upgrade would solve the issue.

I thought of just putting an @ in front of the offending code, IE: <?php if (@$searchField['requiresLabel']): ?>, <?php echo @$searchField['html'] ?> and <?php if (@$searchField['description']): ?> but wanted to check with you guys first in case that would just mask a bigger issue.

I've attached a screen shot of one of the error log entries, the e_blast_general.ini.php file, and the e_blast_press_release.ini.php file.

Any Thoughts?

Thanks,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!

Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By daniel - September 21

Hey Jerry,

In this case, putting an @ in an if condition - when you're just checking for the existence of a value - is generally "safe" though it's no longer considered best practice. A fairly simple and better practice method to avoid the notice is with the empty() function, which checks "does this variable exist and contain a nonzero value?" So instead of this:

<?php if (@$searchField['requiresLabel']): ?>

You would use:

<?php if (!empty($searchField['requiresLabel'])): ?>

Let me know if that helps!

Thanks,

Daniel
Technical Lead
interactivetools.com

By gkornbluth - September 21

Hey Daniel,

Glad I asked. 

I'll give it a  try.

Any idea why this is happening in the first place?

Thanks

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!

Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By daniel - September 21

Hey Jerry,

Apologies, I didn't realize at first this was happening on a CMSB admin page!

It looks like this error shows up if a section isn't configured with any search fields in the section editor (under the "Sorting" tab when editing a section). If you add any search field (or just "_all_"  to restore the default search bar) it should get rid of the errors.

From what I can see, your changes are probably sufficient, but here's a more "official" patch that should fix the errors in that section:

      <!-- simple search -->
      <?php $searchField = getSearchField($primarySearchRow, 'PRIMARY'); ?>
      <?php if (!empty($searchField)): ?>
        <?php if ($searchField['requiresLabel']): ?>
          <div class="row" style="margin-bottom: 5px;">
            <div class="col-md-2">
              <label class="control-label">
                <?php echo $searchField['label'] ?>
              </label>
            </div>
            <div class="col-md-10">
              <?php echo $searchField['html'] ?>
            </div>
          </div>
        <?php else: ?>
          <div class="row" style="margin-bottom: 5px;">
            <div class="col-md-12">
              <?php echo $searchField['html'] ?>
            </div>
            <?php if ($searchField['description']): ?>
              <div class="help-block col-md-12">
                <?php echo $searchField['description']; ?>
              </div>
            <?php endif; ?>
          </div>
        <?php endif ?>
      <?php endif; ?>

This would replace lines 114-137 in /cmsb/lib/menus/list.php (the original version, before your changes)

Let me know if you have any other questions!

Thanks,

Daniel
Technical Lead
interactivetools.com

By gkornbluth - September 21 - edited: September 21

Thanks Daniel,

Appreciate your effort. I'll apply that solution

Is that going to be implemented going forward?

There's an instruction that comes up in the editor when you go to enter the search criteria that says:

Disabling Search If you don't want any search options displayed just leave the box above blank.

This seems contrary to the code that was there in lists.php

Jerry

The first CMS Builder reference book is now available on-line!

Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By daniel - September 21

Hey Jerry,

Yes - I'll get that patch in the next CMSB release so you don't have to worry about it being overwritten in future updates.

I believe this specific error is new in PHP 7.4, so it likely worked to disable the search fields in this way when it was written. But it's not something we see commonly used, so the conditions for the error are pretty rare.

In any case, thanks for reporting this!

Daniel
Technical Lead
interactivetools.com

By gkornbluth - September 21

Glad to help

Have a great rest of the week (and beyond...)

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!

Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php