Make WordPress Core

Changeset 32989


Ignore:
Timestamp:
06/28/2015 02:55:33 PM (8 years ago)
Author:
jorbin
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r32963 r32989  
    34173417
    34183418/**
     3419 * Marks a constructor as deprecated and informs when it has been used.
     3420 *
     3421 * Similar to _deprecated_function(), but with different strings. Used to
     3422 * remove PHP4 style constructors.
     3423 *
     3424 * The current behavior is to trigger a user error if WP_DEBUG is true.
     3425 *
     3426 * This function is to be used in every PHP4 style constructor method that is deprecated.
     3427 *
     3428 * @since 4.3.0
     3429 *
     3430 * @access private
     3431 *
     3432 * @param string $class   The class containing the deprecated constructor.
     3433 * @param string $version The version of WordPress that deprecated the function.
     3434 */
     3435function _deprecated_constructor( $class, $version ) {
     3436
     3437    /**
     3438     * Fires when a deprecated constructor is called.
     3439     *
     3440     * @since 4.3.0
     3441     *
     3442     * @param string $class   The class containing the deprecated constructor.
     3443     * @param string $version The version of WordPress that deprecated the function.
     3444     */
     3445    do_action( 'deprecated_constructor_run', $class, $version );
     3446
     3447    /**
     3448     * Filter whether to trigger an error for deprecated functions.
     3449     *
     3450     * @since 4.3.0
     3451     *
     3452     * @param bool $trigger Whether to trigger the error for deprecated functions. Default true.
     3453     */
     3454    if ( WP_DEBUG && apply_filters( 'deprecated_constructor_trigger_error', true ) ) {
     3455        if ( function_exists( '__' ) ) {
     3456            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>' ) );
     3457        } else {
     3458            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>' ) );
     3459        }
     3460    }
     3461
     3462}
     3463
     3464/**
    34193465 * Mark a file as deprecated and inform when it has been used.
    34203466 *
Note: See TracChangeset for help on using the changeset viewer.