Title: Undefined array key &#8220;before_widget&#8221; / &#8220;after_widget&#8221; (PHP 8)
Last modified: March 7, 2026

---

# Undefined array key “before_widget” / “after_widget” (PHP 8)

 *  Resolved [tonisbramanis](https://wordpress.org/support/users/tonisbramanis/)
 * (@tonisbramanis)
 * [3 months ago](https://wordpress.org/support/topic/undefined-array-key-before_widget-after_widget-php-8/)
 * Undefined array key “before_widget” and “after_widget” in `siteorigin-widget.
   class.php` (PHP 8)
 * Description
 * When a widget from the Widgets Bundle is rendered in a context where `$args` 
   is passed without the standard sidebar keys `before_widget` and `after_widget`,
   PHP 8 triggers:
 * **Error:** `Undefined array key "before_widget"` (and similarly `"after_widget"`)
 * **File:** `so-widgets-bundle/base/siteorigin-widget.class.php`
   **Lines:** 250
   and 258
 * The code does:
 *     ```wp-block-code
       echo $args['before_widget'];
       // ...
       echo $args['after_widget'];
       ```
   
 * If `$args` does not contain these keys (e.g. when the widget is used outside 
   a classic sidebar or with a theme/block that omits them), the array access causes
   the notice.Steps to reproduce
    1. Use WordPress with PHP 8.x and SiteOrigin Widgets Bundle.
    2. Render a Widgets Bundle widget in a context where the caller does not pass `
       $args['before_widget']` and `$args['after_widget']` (e.g. custom widget area
       that omits these, or a block/template that calls the widget with a minimal `
       $args` array).
    3. Load the page or view that renders the widget.
    4. Observe the PHP notice (or enable error logging and check the log).
 * Expected vs actual
    - **Expected:** Widget outputs without PHP notices; missing wrapper markup is
      handled safely.
    - **Actual:** PHP throws “Undefined array key ‘before_widget'” (and ‘after_widget’)
      when those keys are not present in `$args`.
 * Suggested fix
 * Use the null coalescing operator so missing keys do not trigger a notice:
 *     ```wp-block-code
       echo $args['before_widget'] ?? '';
       // ...
       echo $args['after_widget'] ?? '';
       ```
   
 * This keeps backward compatibility: when the keys exist, behavior is unchanged;
   when they are missing, nothing is echoed.Version information
    - **WordPress:** [e.g. 6.4.x]
    - **PHP:** 8.x
    - **SiteOrigin Widgets Bundle:** 1.71.0 (or the version where the issue was 
      seen)
    - **Active theme:** [theme name and version]
 * Environment / notes
    - The plugin is otherwise working; the issue appears only when `$args` is passed
      without `before_widget`/`after_widget`.
    - No other plugins were disabled for this report; the fix was verified locally
      by adding `?? ''` as above.

Viewing 1 replies (of 1 total)

 *  Plugin Support [Andrew Misplon](https://wordpress.org/support/users/misplon/)
 * (@misplon)
 * [3 months ago](https://wordpress.org/support/topic/undefined-array-key-before_widget-after_widget-php-8/#post-18843873)
 * Hi, thanks for posting and getting in touch.
 * Which version of the Widgets Bundle is in use on the site in question?
 * The widget() method normalizes $args with wp_parse_args() before the lines you
   referenced, setting before_widget and after_widget to empty strings when those
   keys are missing:
    - Guard (develop lines 177-182): [https://github.com/siteorigin/so-widgets-bundle/blob/develop/base/siteorigin-widget.class.php#L177-L182](https://github.com/siteorigin/so-widgets-bundle/blob/develop/base/siteorigin-widget.class.php#L177-L182)
    - Guard (1.71.0 lines 177-182): [https://github.com/siteorigin/so-widgets-bundle/blob/1.71.0/base/siteorigin-widget.class.php#L177-L182](https://github.com/siteorigin/so-widgets-bundle/blob/1.71.0/base/siteorigin-widget.class.php#L177-L182)
    - Reported accesses (develop lines 249-258): [https://github.com/siteorigin/so-widgets-bundle/blob/develop/base/siteorigin-widget.class.php#L249-L258](https://github.com/siteorigin/so-widgets-bundle/blob/develop/base/siteorigin-widget.class.php#L249-L258)
      Because $args is normalized earlier in the same method, those array accesses
      should not produce an Undefined array key notice in this code path.
 * If you can let us know the Widgets Bundle version in use and if possible, upload
   a copy of base/siteorigin-widget.class.php from the site in question to PasteBin.
   com and post the link here, we’ll take a look and go from there.
 * Cheers

Viewing 1 replies (of 1 total)

You must be [logged in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fundefined-array-key-before_widget-after_widget-php-8%2F%3Foutput_format%3Dmd&locale=en_US)
to reply to this topic.

 * ![](https://ps.w.org/so-widgets-bundle/assets/icon.svg?rev=2556862)
 * [SiteOrigin Widgets Bundle](https://wordpress.org/plugins/so-widgets-bundle/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/so-widgets-bundle/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/so-widgets-bundle/)
 * [Active Topics](https://wordpress.org/support/plugin/so-widgets-bundle/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/so-widgets-bundle/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/so-widgets-bundle/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Andrew Misplon](https://wordpress.org/support/users/misplon/)
 * Last activity: [3 months ago](https://wordpress.org/support/topic/undefined-array-key-before_widget-after_widget-php-8/#post-18843873)
 * Status: resolved