wppaste
WordPress

WP_View_Config_Data::remove_properties( mixed $current, mixed $spec ): mixed

Since
7.1.0
Source
wp-includes/class-wp-view-config-data.php:599
Removes the properties a spec names from the current value.

Description

The mirror of merge_properties(), applied at every nesting level: a list in $spec names entries to delete from $current — associative keys are unset, and list members are matched by identity (list_item_identity) and dropped — while an associative $spec recurses into each named entry to prune from within it. A name absent from $current is ignored, and a list is renumbered after members are removed so it keeps sequential keys.

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

$currentmixed
The current value.
$specmixed
The names to remove from it.

Return value

mixed
The pruned value.

Performance profile

How much work a call to WP_View_Config_Data::remove_properties() 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
5–22

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
2

2 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::remove_properties() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always5–7none
is_array($current) && is_array($spec) && !array_is_list()17–19array_is_list(), array_is_list()
is_array($current) && is_array($spec) && array_is_list()20–22array_is_list(), array_is_list(), array_values()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev655–2214
8.5655–2214
8.4655–2214
8.3655–2214
8.2655–2214
8.1655–22142 fewer instructions than PHP 7.4
7.4675–2314

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 · 4

Used by · 2

Source code

	private function remove_properties( $current, $spec ) {		if ( ! is_array( $current ) || ! is_array( $spec ) ) {			return $current;		} 		$current_is_list = array_is_list( $current ); 		if ( array_is_list( $spec ) ) {			// Each entry names something to delete from the current value.			foreach ( $spec as $name ) {				if ( $current_is_list ) {					$current = $this->remove_list_member( $current, $name );				} else {					unset( $current[ $name ] );				}			}		} else {			// Each key names an entry to recurse into and prune from within.			foreach ( $spec as $name => $subspec ) {				if ( $current_is_list ) {					foreach ( $current as $index => $member ) {						if ( $this->list_item_identity( $member ) === (string) $name ) {							$current[ $index ] = $this->remove_properties( $member, $subspec );							break;						}					}				} elseif ( array_key_exists( $name, $current ) ) {					$current[ $name ] = $this->remove_properties( $current[ $name ], $subspec );				}			}		} 		// Renumber so a list from which a member was removed keeps sequential keys.		return $current_is_list ? array_values( $current ) : $current;	}

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.