Make WordPress Core

Changeset 63427


Ignore:
Timestamp:
09/01/2026 08:09:39 PM (13 days ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Use is_iterable() instead of manual array or Traversable checks.

PHP offers is_iterable() for the “array or Traversable” test that is otherwise written as a compound condition:

// Before
if ( is_array( $value ) || $value instanceof Traversable ) {

// After
if ( is_iterable( $value ) ) {

This replaces that idiom where it occurs.

Why this is safe

is_iterable() returns true for arrays and for objects implementing Traversable, and false for everything else, the same set the compound condition described, with no edge cases in between. It has been available since PHP 7.1, and WordPress currently requires PHP 7.4 or greater, so no compatibility shim is needed. Only the conditions themselves change; no surrounding logic is touched.

Developed in https://github.com/WordPress/wordpress-develop/pull/13016.

Follow-up to r61700.

Props Soean.
See #65818.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/ai-client/adapters/class-wp-ai-client-http-client.php

    r62753 r63427  
    212212                }
    213213
    214                 if ( is_array( $headers ) || $headers instanceof Traversable ) {
     214                if ( is_iterable( $headers ) ) {
    215215                        foreach ( $headers as $name => $value ) {
    216216                                $response = $response->withHeader( $name, $value );
Note: See TracChangeset for help on using the changeset viewer.