PHP8 Error log warning: “Trying to access array offset on false”
-
Hi! I’m reviewing all my plugins before our big upgrade from PHP 7.3 to PHP 8.3 and the Donorbox plugin has a small error that causes notices in the logs.
Here’s the warning:
PHP Warning: Trying to access array offset on false in /Users/jer/Sites/dev.gv/wp-content/plugins/donorbox-donation-form/donorbox_embed_campaign.php on line 128It’s from this line of code in
donorbox_embed_campaign.php:128generate_donorbox_iframe_src():$options = get_option('donorbox_embed_campaign_options');
$donorbox_campaign_input = $options['donorbox_embed_campaign_id']; // get the campaign idThe cause is obvious: The code accesses the
$optionsassuming that it’s an array, but in this case, it’s false, because I never set up the option (I just use the shortcode with the URL in it).The fix is simple and harmless, just check that the array element exists before using it:
$options = get_option('donorbox_embed_campaign_options');
$donorbox_campaign_input = '';
if (!empty($options['donorbox_embed_campaign_id'])) {
$donorbox_campaign_input = $options['donorbox_embed_campaign_id']; // get the campaign id
}Thank you in advance for patching this in the next version 🙏🏻
BTW if you have a Github please let me know, I couldn’t find a repository in your account for this WP plugin.
The topic ‘PHP8 Error log warning: “Trying to access array offset on false”’ is closed to new replies.