wp-includes/rest-api/endpoints/class-wp-rest-view-config-controller.php:190Recursively casts empty arrays to objects where the schema types them as objects.
$valuemixed$schemaarraymixed protected function cast_empty_objects( $value, $schema ) { if ( ! is_array( $value ) || ! is_array( $schema ) ) { return $value; } if ( isset( $schema['oneOf'] ) || isset( $schema['anyOf'] ) ) { $branches = $schema['oneOf'] ?? $schema['anyOf']; if ( array() === $value ) { foreach ( $branches as $branch ) { if ( is_array( $branch ) && in_array( 'object', (array) ( $branch['type'] ?? array() ), true ) ) { return (object) array(); } } } return $value; } $types = (array) ( $schema['type'] ?? array() ); if ( in_array( 'array', $types, true ) && isset( $schema['items'] ) ) { foreach ( $value as $index => $item ) { $value[ $index ] = $this->cast_empty_objects( $item, $schema['items'] ); } return $value; } if ( in_array( 'object', $types, true ) ) { if ( isset( $schema['properties'] ) ) { foreach ( $schema['properties'] as $property => $property_schema ) { if ( array_key_exists( $property, $value ) ) { $value[ $property ] = $this->cast_empty_objects( $value[ $property ], $property_schema ); } } } if ( isset( $schema['additionalProperties'] ) && is_array( $schema['additionalProperties'] ) ) { foreach ( $value as $key => $item ) { if ( isset( $schema['properties'][ $key ] ) ) { continue; } $value[ $key ] = $this->cast_empty_objects( $item, $schema['additionalProperties'] ); } } // Empty object-typed arrays must serialize as {} to match the schema. if ( array() === $value ) { return (object) array(); } } return $value; }Introduced in 7.1.0.
Signature, return type and hooks compared across 1 parsed release.
src/wp-includes/rest-api/endpoints/class-wp-rest-view-config-controller.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.