WP_Site_Health_Auto_Updates::test_constants( string $constant, bool|string|array $value ): array|null
- Since
- 5.2.0, 5.5.1
- Source
wp-admin/includes/class-wp-site-health-auto-updates.php:72
Compatibility
- WordPress
- since 5.5.1
- 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
$constantstring- The name of the constant to check.
$valuebool|string|array- The value that the constant should be, if set, or an array of acceptable values.
Return value
array|null- The test results if there are any constants set incorrectly, or null if the test passed.
Performance profile
How much work a call to WP_Site_Health_Auto_Updates::test_constants() 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
- Trivial
- Scaling
- Constant
- Instructions
- 8–39
- Plugin surface
- None
- Called by
- 1
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 40.
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 it touches
- hookthird-party callbacks
apply_filters()one call below WP_Site_Health_Auto_Updates::test_constants()
Further down the call graph this can also reach option, cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
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_Site_Health_Auto_Updates::test_constants() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!defined() | 8 | defined() |
defined() && $acceptable_values | 14 | defined(), constant() |
defined() && !$acceptable_values | 39 | defined(), constant(), __(), constant(), var_export(), esc_html(), sprintf() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 40 | 8–39 | 2 | |
| 8.5 | 40 | 8–39 | 2 | |
| 8.4 | 40 | 8–39 | 2 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 43 | 8–42 | 2 | |
| 8.2 | 43 | 8–42 | 2 | |
| 8.1 | 43 | 8–42 | 2 | |
| 7.4 | 43 | 8–42 | 2 |
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
- __()Retrieves the translation of $text.
- esc_html()Escaping for HTML blocks.
Used by · 1
- WP_Site_Health_Auto_Updates::run_tests()Runs tests to determine if auto-updates can run.
Source code
public function test_constants( $constant, $value ) { $acceptable_values = (array) $value; if ( defined( $constant ) && ! in_array( constant( $constant ), $acceptable_values, true ) ) { return array( 'description' => sprintf( /* translators: 1: Name of the constant used. 2: Value of the constant used. */ __( 'The %1$s constant is defined as %2$s' ), "<code>$constant</code>", '<code>' . esc_html( var_export( constant( $constant ), true ) ) . '</code>' ), 'severity' => 'fail', ); } return null; }Changelog
Introduced in 5.2.0. One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
array to array|null.verified against source$value parameter can accept an array.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 tag, from
src/wp-admin/includes/class-wp-site-health-auto-updates.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.