WP_View_Config_Data::list_item_identity( mixed $item ): string|null
- Since
- 7.1.0
- Source
wp-includes/class-wp-view-config-data.php:732
Description
The identity is simply the member's value cast to a string, regardless of which key carries it: a bare scalar is its own identity, and a map is identified by the value of the first of the well-known identity keys (id, slug, field) it carries. Because the key is not part of the identity, a bare field like 'f3' matches any map carrying that value, whether it appears as array( 'id' => 'f3' ), array( 'slug' => 'f3' ), and so on — this lets the same shorthand target lists keyed by different fields. Casting to string keeps numeric identities matching whether they arrive as an int or a string. Anything else (e.g. a nested list) has no identity and never matches, so it is always appended.
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
$itemmixed- The list member.
Return value
string|null- The identity, or null when the member has none.
Performance profile
How much work a call to WP_View_Config_Data::list_item_identity() 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
- 5–20
- Plugin surface
- None
- Called by
- 3
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 24.
Nothing here hands control to plugin code.
3 places in core call this, so the cost is paid more often than your own code shows.
What one call costs · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_View_Config_Data::list_item_identity() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 5–6 | none |
!is_scalar($item) && is_array($item) | 10–20 | array_is_list() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 24 | 5–20 | 7 | |
| 8.5 | 24 | 5–20 | 7 | |
| 8.4 | 24 | 5–20 | 7 | |
| 8.3 | 24 | 5–20 | 7 | |
| 8.2 | 24 | 5–20 | 7 | |
| 8.1 | 24 | 5–20 | 7 | 4 fewer instructions than PHP 7.4 |
| 7.4 | 28 | 7–24 | 7 |
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 · 1
- array_is_list()Polyfill for `array_is_list()` function added in PHP 8.1.
Used by · 3
- WP_View_Config_Data::merge_list_by_identity()Merges an incoming list into the current one by member identity.
- WP_View_Config_Data::remove_list_member()Removes the first list member matching an identity, leaving the rest.
- WP_View_Config_Data::remove_properties()Removes the properties a spec names from the current value.
Source code
private function list_item_identity( $item ) { if ( is_scalar( $item ) ) { return (string) $item; } if ( is_array( $item ) && ! array_is_list( $item ) ) { foreach ( array( 'id', 'slug', 'field' ) as $key ) { if ( isset( $item[ $key ] ) && is_scalar( $item[ $key ] ) ) { return (string) $item[ $key ]; } } } return null; }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.