wppaste
WordPress

WP_View_Config_Data::strip_nulls( mixed $value ): mixed

Since
7.1.0
Source
wp-includes/class-wp-view-config-data.php:468
Recursively drops every property whose value is 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 null property 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

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
4–15

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 26.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
4

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.

WhenInstructionsCalls it makes
!is_array($value)4none
is_array($value) && !array_is_list()11–12array_is_list()
is_array($value) && array_is_list()14–15array_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

Used by · 4

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.