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, 2022   (RSS)

By gkornbluth - September 20, 2022 - edited: September 20, 2022

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, 2022

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, 2022

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 gkornbluth - September 21, 2022 - edited: September 21, 2022

Thanks Daniel,

No errors now...

Just curious if I did the right thing, Daniel.

One of the offending lines was:

<?php echo $searchField['html'] ?>

So I surrounded it with an if to check if the value was empty,

<?php if (!empty($searchField['html'])): // added 9/12/22 ?>
<?php echo $searchField['html'] ?>
<?php endif ?>

I'm still interested to find out why I got these errors in the first place.

At any rate, here's what I did in case someone else come up with the same kind of issue. (starts at line 113 in version 3.56 in cmsAdmin/lib/menus/default/list.php)

<!-- simple search -->
<?php $searchField = getSearchField($primarySearchRow, 'PRIMARY'); ?>
<?php // if ($searchField['requiresLabel']): ?>
<?php if (!empty($searchField['requiresLabel'])): // added 9/12/22 per Daniel ?>
<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 if (!empty($searchField['html'])): // added 9/12/22 ?>
<?php echo $searchField['html'] ?>
<?php endif ?>
</div>
<?php // if ($searchField['description']): ?>
<?php if (!empty($searchField['ddescription'])): // added 9/12/22 per Daniel ?>
<div class="help-block col-md-12">
<?php echo $searchField['description']; ?>
</div>
<?php endif; ?>
</div>
<?php endif ?>

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 gkornbluth - September 21, 2022 - edited: September 21, 2022

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, 2022

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, 2022

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