Make WordPress Core


Ignore:
Timestamp:
11/16/2021 01:41:23 AM (3 years ago)
Author:
hellofromTonya
Message:

Widgets: Use isset() in WP_Widget:: display_callback() to support ArrayIterator and ArrayObject.

[33696] introduced support returning ArrayIterator and ArrayObject objects from WP_Widget::get_settings().

Per the PHP manual, array_key_exists() stopped supporting this in PHP 8.0.0 and deprecated in PHP 7.4.0.

For backward compatibility reasons, array_key_exists() will also return true if key is a property defined within an object given as array. This behaviour is deprecated as of PHP 7.4.0, and removed as of PHP 8.0.0.

This commit uses isset() instead of array_key_exists() which is supported on all current versions of PHP.

Includes unit tests.

Ref:

Follow-up to [32602], [33696].

Props dlh, hellofromTonya, jrf, sergeybiryukov.
Fixes #52728.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-widget.php

    r51070 r52173  
    366366        $instances = $this->get_settings();
    367367
    368         if ( array_key_exists( $this->number, $instances ) ) {
     368        if ( isset( $instances[ $this->number ] ) ) {
    369369            $instance = $instances[ $this->number ];
    370370
Note: See TracChangeset for help on using the changeset viewer.