Add Deprecated Constructor Function

This function is one that can be called in core to indicate that a PHP4 style constructor is used. PHP4 style constructors are deprecated in PHP7.

Props jorbin, DrewAPicture for docs
See #31982


Built from https://develop.svn.wordpress.org/trunk@32989


git-svn-id: http://core.svn.wordpress.org/trunk@32960 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Aaron Jorbin 2015-06-28 14:56:24 +00:00
parent c9307fc95a
commit a6ebaefb92
2 changed files with 47 additions and 1 deletions

View File

@ -3415,6 +3415,52 @@ function _deprecated_function( $function, $version, $replacement = null ) {
} }
} }
/**
* Marks a constructor as deprecated and informs when it has been used.
*
* 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.
*
* @since 4.3.0
*
* @access private
*
* @param string $class The class containing the deprecated constructor.
* @param string $version The version of WordPress that deprecated the function.
*/
function _deprecated_constructor( $class, $version ) {
/**
* Fires when a deprecated constructor is called.
*
* @since 4.3.0
*
* @param string $class The class containing the deprecated constructor.
* @param string $version The version of WordPress that deprecated the function.
*/
do_action( 'deprecated_constructor_run', $class, $version );
/**
* Filter whether to trigger an error for deprecated functions.
*
* @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( '__' ) ) {
trigger_error( sprintf( __( 'The called constructor method for %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $class, $version, '<pre>__construct()</pre>' ) );
} else {
trigger_error( sprintf( 'The called constructor method for %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $class, $version, '<pre>__construct()</pre>' ) );
}
}
}
/** /**
* Mark a file as deprecated and inform when it has been used. * Mark a file as deprecated and inform when it has been used.
* *

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.3-alpha-32988'; $wp_version = '4.3-alpha-32989';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.