_deprecated_constructor( string $class_name, string $version, string $parent_class = '' )
- Since
- 4.3.0, 4.5.0, 5.4.0, 5.4.0
- Source
wp-includes/functions.php:5603
Description
Similar to _deprecated_function(), but with different strings. Used to remove PHP4-style constructors.
The current behavior is to trigger a user error if WP_DEBUG is true.
This function is to be used in every PHP4-style constructor method that is deprecated.
Compatibility
- WordPress
- since 5.4.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
$class_namestring- The class containing the deprecated constructor.
$versionstring- The version of WordPress that deprecated the function.
$parent_classstringoptional- The parent class calling the deprecated constructor.
Default empty string.Default:''
Performance profile
How much work a call to _deprecated_constructor() 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
- 12–39
- Plugin surface
- 2 hooks
- Called by
- 11
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 67.
Third-party callbacks on 'deprecated_constructor_run', 'deprecated_constructor_trigger_error' run inside this call, and their cost is not bounded by anything here.
11 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
do_action()called directly
Further down the call graph this can also reach query, option, cache, serialize 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 · 4 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost _deprecated_constructor() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 12 | do_action() |
!apply_filters() | 17 | do_action(), apply_filters() |
apply_filters() && !function_exists() | 34–36 | do_action(), apply_filters(), function_exists(), sprintf(), wp_trigger_error() |
apply_filters() && function_exists() | 38–39 | do_action(), apply_filters(), function_exists(), __(), sprintf(), wp_trigger_error() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 67 instructions, 12–39 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.
Hooks and filters fired · 2
2 hooks fire while _deprecated_constructor() runs, in this order:
- do_action( deprecated_constructor_run )actionline 5615 (+12 into the body)
Fires when a deprecated constructor is called.
- apply_filters( deprecated_constructor_trigger_error )filterline 5626 (+23 into the body)
Filters whether to trigger an error for deprecated functions.
Uses · 4
- do_action()Calls the callback functions that have been added to an action hook.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- __()Retrieves the translation of $text.
- wp_trigger_error()Generates a user-level error/warning/notice/deprecation message.
Used by · 11
- POMO_CachedFileReader::POMO_CachedFileReader()PHP4 constructor.
- POMO_CachedIntFileReader::POMO_CachedIntFileReader()PHP4 constructor.
- POMO_FileReader::POMO_FileReader()PHP4 constructor.
- POMO_Reader::POMO_Reader()PHP4 constructor.
- POMO_StringReader::POMO_StringReader()PHP4 constructor.
- Services_JSON::Services_JSON()PHP4 constructor.
- Services_JSON_Error::Services_JSON_Error()PHP4 constructor.
- Translation_Entry::Translation_Entry()PHP4 constructor.
- WP_User_Search::WP_User_Search()PHP4 Constructor - Sets up the object properties.
- WP_Widget::WP_Widget()PHP4 constructor.
- WP_Widget_Factory::WP_Widget_Factory()PHP4 constructor.
Source code
function _deprecated_constructor( $class_name, $version, $parent_class = '' ) { /** * Fires when a deprecated constructor is called. * * @since 4.3.0 * @since 4.5.0 Added the `$parent_class` parameter. * * @param string $class_name The class containing the deprecated constructor. * @param string $version The version of WordPress that deprecated the function. * @param string $parent_class The parent class calling the deprecated constructor. */ do_action( 'deprecated_constructor_run', $class_name, $version, $parent_class ); /** * Filters whether to trigger an error for deprecated functions. * * `WP_DEBUG` must be true in addition to the filter evaluating to true. * * @since 4.3.0 * * @param bool $trigger Whether to trigger the error for deprecated functions. Default true. */ if ( WP_DEBUG && apply_filters( 'deprecated_constructor_trigger_error', true ) ) { if ( function_exists( '__' ) ) { if ( $parent_class ) { $message = sprintf( /* translators: 1: PHP class name, 2: PHP parent class name, 3: Version number, 4: __construct() method. */ __( 'The called constructor method for %1$s class in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.' ), $class_name, $parent_class, $version, '<code>__construct()</code>' ); } else { $message = sprintf( /* translators: 1: PHP class name, 2: Version number, 3: __construct() method. */ __( 'The called constructor method for %1$s class is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $class_name, $version, '<code>__construct()</code>' ); } } else { if ( $parent_class ) { $message = sprintf( 'The called constructor method for %1$s class in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.', $class_name, $parent_class, $version, '<code>__construct()</code>' ); } else { $message = sprintf( 'The called constructor method for %1$s class is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $class_name, $version, '<code>__construct()</code>' ); } } wp_trigger_error( '', $message, E_USER_DEPRECATED ); }}Changelog
Introduced in 4.3.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$parent_class parameter.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 tag, from
src/wp-includes/functions.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.