Normalizes schema empty object defaults.
Description
Converts empty array defaults to objects when the schema type is ‘object’ to ensure proper JSON serialization as {} instead of [].
Parameters
- mixed> $schema The schema array.
Source
private function normalize_schema_empty_object_defaults( array $schema ): array {
if ( isset( $schema['type'] ) && 'object' === $schema['type'] && isset( $schema['default'] ) ) {
$default = $schema['default'];
if ( is_array( $default ) && empty( $default ) ) {
$schema['default'] = (object) $default;
}
}
return $schema;
}
Changelog
| Version | Description |
|---|---|
| 6.9.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.