WP_Style_Engine_CSS_Rule::add_declarations( string[]|WP_Style_Engine_CSS_Declarations $declarations ): WP_Style_Engine_CSS_Rule
- Since
- 6.1.0, 7.1.0
- Source
wp-includes/style-engine/class-wp-style-engine-css-rule.php:90
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 every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$declarationsstring[]|WP_Style_Engine_CSS_Declarations- An array of declarations (property => value pairs), or a WP_Style_Engine_CSS_Declarations object.
Return value
WP_Style_Engine_CSS_Rule- Returns the object to allow chaining of methods.
Performance profile
How much work a call to WP_Style_Engine_CSS_Rule::add_declarations() 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
- 16–28
- Plugin surface
- None
- Called by
- 1
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 45.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What one call costs · 4 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Style_Engine_CSS_Rule::add_declarations() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$value | 16–22 | none |
| always | 19–25 | ->get_declaration_options() |
| always | 19–25 | ->get_declarations() |
!$value | 22–28 | ->get_declarations(), ->get_declaration_options() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 43 | 16–26 | 7 | 2 fewer instructions than PHP 8.5 |
| 8.5 | 45 | 16–28 | 7 | |
| 8.4 | 45 | 16–28 | 7 | |
| 8.3 | 45 | 16–28 | 7 | |
| 8.2 | 45 | 16–28 | 7 | |
| 8.1 | 45 | 16–28 | 7 | |
| 7.4 | 45 | 16–28 | 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
- WP_Style_Engine_CSS_Declarations::__construct()Constructor for this object.
Used by · 1
- WP_Style_Engine_CSS_Rule::__construct()Constructor.
Source code
public function add_declarations( $declarations ) { $is_declarations_object = ! is_array( $declarations ); $declarations_array = $is_declarations_object ? $declarations->get_declarations() : $declarations; $declaration_options = $is_declarations_object ? $declarations->get_declaration_options() : array(); if ( null === $this->declarations ) { if ( $is_declarations_object ) { $this->declarations = $declarations; return $this; } $this->declarations = new WP_Style_Engine_CSS_Declarations(); } foreach ( $declarations_array as $property => $value ) { $this->declarations->add_declaration( $property, $value, $declaration_options[ $property ] ?? array() ); } return $this; }Changelog
Introduced in 6.1.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
WP_Style_Engine_CSS_Declarations object.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/style-engine/class-wp-style-engine-css-rule.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.