• Resolved MediaArt

    (@mediaart)


    PHP Warning: Undefined array key “enabled” after update to 4.0.13

    After updating Payment Plugins for Stripe WooCommerce to version 4.0.13, the following PHP warning started appearing repeatedly:

    PHP Warning: Undefined array key "enabled" in
    /wp-content/plugins/woo-stripe-payment/includes/class-wc-stripe-product-gateway-option.php on line 113

    The issue is in WC_Stripe_Product_Gateway_Option::get_option():

    public function get_option( $key, $default = null ) {
        if ( ! isset( $this->settings[ $key ] ) && null != $default ) {
            $this->settings[ $key ] = $default;
        }
    
        return $this->settings[ $key ];
    }

    enabled() calls:

    return $this->get_option( 'enabled', false );

    Because the comparison in get_option() is non-strict (null != $default), it evaluates to false when $default is boolean false. Therefore, if the enabled key is missing, the default value is not assigned and the subsequent array access triggers the PHP warning.

    I tested the following fix successfully:

    public function get_option( $key, $default = null ) {
        if ( ! isset( $this->settings[ $key ] ) && null !== $default ) {
            $this->settings[ $key ] = $default;
        }
    
        return $this->settings[ $key ] ?? $default;
    }

    This changes the comparison to strict (!==) and also safely returns the supplied default if the key is absent.

    Could you please include this fix in the next release?

Viewing 1 replies (of 1 total)
  • Plugin Author Clayton R

    (@mrclayton)

    Hi @mediaart

    Thank you for contacting Payment Plugins. That line of code was not changed in version 4.0.13 and has not changed in many versions so the occurrence of that notice isn’t something specific to 4.0.13.

    What version of PHP are you using?

    Could you please include this fix in the next release?

    Yes, we’ll update the code in the next release.

    Kind Regards

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.