WP_View_Config_Data::strip_nulls( mixed $value ): mixed
- Since
- 7.1.0
- Source
wp-includes/class-wp-view-config-data.php:468
null from a value.Description
set() swaps a named key's value in wholesale rather than merging it into the current one, so it has no existing leaf for a nested null to delete the way merge() and replace() do. Stripping nulls here gives a nested null the same "drop the property it names" meaning under set() that it carries everywhere else. The same applies to a list replace() swaps in wholesale. A list is renumbered after a member is removed so removed entries do not leave gaps.
Compatibility
- WordPress
- since 7.1.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in 1 of the 5 tracked releases, added in 7.1.0, and compiles on PHP 7.4 through 8.6-dev.
Parameters
$valuemixed- The value to strip nulls from.
Return value
mixed- The value with every
nullproperty removed, recursively.
Performance profile
How much work a call to WP_View_Config_Data::strip_nulls() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Light
- Scaling
- Scales with input
- Instructions
- 4–15
- Plugin surface
- None
- Called by
- 4
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 26.
Nothing here hands control to plugin code.
4 places in core call this, so the cost is paid more often than your own code shows.
What one call costs · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_View_Config_Data::strip_nulls() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!is_array($value) | 4 | none |
is_array($value) && !array_is_list() | 11–12 | array_is_list() |
is_array($value) && array_is_list() | 14–15 | array_is_list(), array_values() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 26 instructions, 4–15 executed per call, 5 branches. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 2
- array_is_list()Polyfill for `array_is_list()` function added in PHP 8.1.
- WP_View_Config_Data::strip_nulls()Recursively drops every property whose value is `null` from a value.
Used by · 4
- WP_View_Config_Data::apply()Applies a patch to the configuration, top-level key by top-level key.
- WP_View_Config_Data::merge_list_by_identity()Merges an incoming list into the current one by member identity.
- WP_View_Config_Data::merge_properties()Merges an incoming value into the current one, recursing by value shape.
- WP_View_Config_Data::strip_nulls()Recursively drops every property whose value is `null` from a value.
Source code
private function strip_nulls( $value ) { if ( ! is_array( $value ) ) { return $value; } $result = array(); foreach ( $value as $key => $item ) { // A null value drops the property it names. if ( null === $item ) { continue; } $result[ $key ] = $this->strip_nulls( $item ); } // Renumber a list so a removed member does not leave a gap. return array_is_list( $value ) ? array_values( $result ) : $result; }Changelog
Introduced in 7.1.0.
Signature, return type and hooks compared across 1 parsed release.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/class-wp-view-config-data.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.