Make WordPress Core

Ticket #36561: 36561-4-classify-trigger_error-calls.patch

File 36561-4-classify-trigger_error-calls.patch, 13.5 KB (added by jrf, 6 years ago)

Refreshed patch: removed PHP 5.3 compat changes; updated the version mentioned in the @since entries; fixed up the trigger_error() function calls to multi-line for improved readability.

  • src/wp-includes/functions.php

    From ee42a1a9bb8f82481f8d0c5ee165f9327ed12681 Mon Sep 17 00:00:00 2001
    From: jrfnl <jrfnl@users.noreply.github.com>
    Date: Sun, 18 Jun 2017 15:49:43 +0200
    Subject: [PATCH] Deprecated notices should be classified as
     E_(USER_)DEPRECATED.
    
    ---
     src/wp-includes/functions.php              | 170 +++++++++++++++++----
     tests/phpunit/includes/phpunit6/compat.php |   1 +
     tests/phpunit/tests/compat.php             |   2 +-
     3 files changed, 144 insertions(+), 29 deletions(-)
    
    diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php
    index d3dded8078..df23c5186d 100644
    a b function absint( $maybeint ) { 
    45284528 * This function is to be used in every function that is deprecated.
    45294529 *
    45304530 * @since 2.5.0
     4531 * @since 5.4.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE).
    45314532 * @access private
    45324533 *
    45334534 * @param string $function    The function that was called.
    function _deprecated_function( $function, $version, $replacement = null ) { 
    45574558        if ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) {
    45584559                if ( function_exists( '__' ) ) {
    45594560                        if ( ! is_null( $replacement ) ) {
    4560                                 /* translators: 1: PHP function name, 2: Version number, 3: Alternative function name. */
    4561                                 trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $function, $version, $replacement ) );
     4561                                trigger_error(
     4562                                        sprintf(
     4563                                                /* translators: 1: PHP function name, 2: Version number, 3: Alternative function name. */
     4564                                                __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
     4565                                                $function,
     4566                                                $version,
     4567                                                $replacement
     4568                                        ),
     4569                                        E_USER_DEPRECATED
     4570                                );
    45624571                        } else {
    4563                                 /* translators: 1: PHP function name, 2: Version number. */
    4564                                 trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $function, $version ) );
     4572                                trigger_error(
     4573                                        sprintf(
     4574                                                /* translators: 1: PHP function name, 2: Version number. */
     4575                                                __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
     4576                                                $function,
     4577                                                $version
     4578                                        ),
     4579                                        E_USER_DEPRECATED
     4580                                );
    45654581                        }
    45664582                } else {
    45674583                        if ( ! is_null( $replacement ) ) {
    4568                                 trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $function, $version, $replacement ) );
     4584                                trigger_error(
     4585                                        sprintf(
     4586                                                '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
     4587                                                $function,
     4588                                                $version,
     4589                                                $replacement
     4590                                        ),
     4591                                        E_USER_DEPRECATED
     4592                                );
    45694593                        } else {
    4570                                 trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $function, $version ) );
     4594                                trigger_error(
     4595                                        sprintf(
     4596                                                '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.',
     4597                                                $function,
     4598                                                $version
     4599                                        ),
     4600                                        E_USER_DEPRECATED
     4601                                );
    45714602                        }
    45724603                }
    45734604        }
    function _deprecated_function( $function, $version, $replacement = null ) { 
    45854616 *
    45864617 * @since 4.3.0
    45874618 * @since 4.5.0 Added the `$parent_class` parameter.
     4619 * @since 5.4.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE).
    45884620 *
    45894621 * @access private
    45904622 *
    function _deprecated_constructor( $class, $version, $parent_class = '' ) { 
    46274659                                                $parent_class,
    46284660                                                $version,
    46294661                                                '<pre>__construct()</pre>'
    4630                                         )
     4662                                        ),
     4663                                        E_USER_DEPRECATED
    46314664                                );
    46324665                        } else {
    46334666                                trigger_error(
    function _deprecated_constructor( $class, $version, $parent_class = '' ) { 
    46374670                                                $class,
    46384671                                                $version,
    46394672                                                '<pre>__construct()</pre>'
    4640                                         )
     4673                                        ),
     4674                                        E_USER_DEPRECATED
    46414675                                );
    46424676                        }
    46434677                } else {
    function _deprecated_constructor( $class, $version, $parent_class = '' ) { 
    46494683                                                $parent_class,
    46504684                                                $version,
    46514685                                                '<pre>__construct()</pre>'
    4652                                         )
     4686                                        ),
     4687                                        E_USER_DEPRECATED
    46534688                                );
    46544689                        } else {
    46554690                                trigger_error(
    function _deprecated_constructor( $class, $version, $parent_class = '' ) { 
    46584693                                                $class,
    46594694                                                $version,
    46604695                                                '<pre>__construct()</pre>'
    4661                                         )
     4696                                        ),
     4697                                        E_USER_DEPRECATED
    46624698                                );
    46634699                        }
    46644700                }
    function _deprecated_constructor( $class, $version, $parent_class = '' ) { 
    46784714 * This function is to be used in every file that is deprecated.
    46794715 *
    46804716 * @since 2.5.0
     4717 * @since 5.4.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE).
    46814718 * @access private
    46824719 *
    46834720 * @param string $file        The file that was included.
    function _deprecated_file( $file, $version, $replacement = null, $message = '' ) 
    47114748                $message = empty( $message ) ? '' : ' ' . $message;
    47124749                if ( function_exists( '__' ) ) {
    47134750                        if ( ! is_null( $replacement ) ) {
    4714                                 /* translators: 1: PHP file name, 2: Version number, 3: Alternative file name. */
    4715                                 trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $file, $version, $replacement ) . $message );
     4751                                trigger_error(
     4752                                        sprintf(
     4753                                                /* translators: 1: PHP file name, 2: Version number, 3: Alternative file name. */
     4754                                                __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
     4755                                                $file,
     4756                                                $version,
     4757                                                $replacement
     4758                                        ) . $message,
     4759                                        E_USER_DEPRECATED
     4760                                );
    47164761                        } else {
    4717                                 /* translators: 1: PHP file name, 2: Version number. */
    4718                                 trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $file, $version ) . $message );
     4762                                trigger_error(
     4763                                        sprintf(
     4764                                                /* translators: 1: PHP file name, 2: Version number. */
     4765                                                __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
     4766                                                $file,
     4767                                                $version
     4768                                        ) . $message,
     4769                                        E_USER_DEPRECATED
     4770                                );
    47194771                        }
    47204772                } else {
    47214773                        if ( ! is_null( $replacement ) ) {
    4722                                 trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $file, $version, $replacement ) . $message );
     4774                                trigger_error(
     4775                                        sprintf(
     4776                                                '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
     4777                                                $file,
     4778                                                $version,
     4779                                                $replacement
     4780                                        ) . $message,
     4781                                        E_USER_DEPRECATED
     4782                                );
    47234783                        } else {
    4724                                 trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $file, $version ) . $message );
     4784                                trigger_error(
     4785                                        sprintf(
     4786                                                '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.',
     4787                                                $file,
     4788                                                $version
     4789                                        ) . $message,
     4790                                        E_USER_DEPRECATED
     4791                                );
    47254792                        }
    47264793                }
    47274794        }
    function _deprecated_file( $file, $version, $replacement = null, $message = '' ) 
    47454812 * The current behavior is to trigger a user error if WP_DEBUG is true.
    47464813 *
    47474814 * @since 3.0.0
     4815 * @since 5.4.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE).
    47484816 * @access private
    47494817 *
    47504818 * @param string $function The function that was called.
    function _deprecated_argument( $function, $version, $message = null ) { 
    47744842        if ( WP_DEBUG && apply_filters( 'deprecated_argument_trigger_error', true ) ) {
    47754843                if ( function_exists( '__' ) ) {
    47764844                        if ( ! is_null( $message ) ) {
    4777                                 /* translators: 1: PHP function name, 2: Version number, 3: Optional message regarding the change. */
    4778                                 trigger_error( sprintf( __( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s' ), $function, $version, $message ) );
     4845                                trigger_error(
     4846                                        sprintf(
     4847                                                /* translators: 1: PHP function name, 2: Version number, 3: Optional message regarding the change. */
     4848                                                __( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s' ),
     4849                                                $function,
     4850                                                $version,
     4851                                                $message
     4852                                        ),
     4853                                        E_USER_DEPRECATED
     4854                                );
    47794855                        } else {
    4780                                 /* translators: 1: PHP function name, 2: Version number. */
    4781                                 trigger_error( sprintf( __( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $function, $version ) );
     4856                                trigger_error(
     4857                                        sprintf(
     4858                                                /* translators: 1: PHP function name, 2: Version number. */
     4859                                                __( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
     4860                                                $function,
     4861                                                $version
     4862                                        ),
     4863                                        E_USER_DEPRECATED
     4864                                );
    47824865                        }
    47834866                } else {
    47844867                        if ( ! is_null( $message ) ) {
    4785                                 trigger_error( sprintf( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s', $function, $version, $message ) );
     4868                                trigger_error(
     4869                                        sprintf(
     4870                                                '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s',
     4871                                                $function,
     4872                                                $version,
     4873                                                $message
     4874                                        ),
     4875                                        E_USER_DEPRECATED
     4876                                );
    47864877                        } else {
    4787                                 trigger_error( sprintf( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.', $function, $version ) );
     4878                                trigger_error(
     4879                                        sprintf(
     4880                                                '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.',
     4881                                                $function,
     4882                                                $version
     4883                                        ),
     4884                                        E_USER_DEPRECATED
     4885                                );
    47884886                        }
    47894887                }
    47904888        }
    function _deprecated_argument( $function, $version, $message = null ) { 
    48024900 * functions, and so generally does not need to be called directly.
    48034901 *
    48044902 * @since 4.6.0
     4903 * @since 5.4.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE).
    48054904 * @access private
    48064905 *
    48074906 * @param string $hook        The hook that was used.
    function _deprecated_hook( $hook, $version, $replacement = null, $message = null 
    48334932        if ( WP_DEBUG && apply_filters( 'deprecated_hook_trigger_error', true ) ) {
    48344933                $message = empty( $message ) ? '' : ' ' . $message;
    48354934                if ( ! is_null( $replacement ) ) {
    4836                         /* translators: 1: WordPress hook name, 2: Version number, 3: Alternative hook name. */
    4837                         trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $hook, $version, $replacement ) . $message );
     4935                        trigger_error(
     4936                                sprintf(
     4937                                        /* translators: 1: WordPress hook name, 2: Version number, 3: Alternative hook name. */
     4938                                        __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
     4939                                        $hook,
     4940                                        $version,
     4941                                        $replacement
     4942                                ) . $message,
     4943                                E_USER_DEPRECATED
     4944                        );
    48384945                } else {
    4839                         /* translators: 1: WordPress hook name, 2: Version number. */
    4840                         trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $hook, $version ) . $message );
     4946                        trigger_error(
     4947                                sprintf(
     4948                                        /* translators: 1: WordPress hook name, 2: Version number. */
     4949                                        __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
     4950                                        $hook,
     4951                                        $version
     4952                                ) . $message,
     4953                                E_USER_DEPRECATED
     4954                        );
    48414955                }
    48424956        }
    48434957}
    function _doing_it_wrong( $function, $message, $version ) { 
    48965010                                __( 'https://wordpress.org/support/article/debugging-in-wordpress/' )
    48975011                        );
    48985012                        /* translators: Developer debugging message. 1: PHP function name, 2: Explanatory message, 3: Version information message. */
    4899                         trigger_error( sprintf( __( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s' ), $function, $message, $version ) );
     5013                        trigger_error( sprintf( __( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s' ), $function, $message, $version ), E_USER_NOTICE );
    49005014                } else {
    49015015                        if ( is_null( $version ) ) {
    49025016                                $version = '';
    function _doing_it_wrong( $function, $message, $version ) { 
    49075021                                ' Please see <a href="%s">Debugging in WordPress</a> for more information.',
    49085022                                'https://wordpress.org/support/article/debugging-in-wordpress/'
    49095023                        );
    4910                         trigger_error( sprintf( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s', $function, $message, $version ) );
     5024                        trigger_error( sprintf( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s', $function, $message, $version ), E_USER_NOTICE );
    49115025                }
    49125026        }
    49135027}
  • tests/phpunit/includes/phpunit6/compat.php

    diff --git a/tests/phpunit/includes/phpunit6/compat.php b/tests/phpunit/includes/phpunit6/compat.php
    index de9b0bccac..dcc99e9a76 100644
    a b if ( class_exists( 'PHPUnit\Runner\Version' ) && version_compare( PHPUnit\Runner 
    55        class_alias( 'PHPUnit\Framework\TestCase', 'PHPUnit_Framework_TestCase' );
    66        class_alias( 'PHPUnit\Framework\Exception', 'PHPUnit_Framework_Exception' );
    77        class_alias( 'PHPUnit\Framework\ExpectationFailedException', 'PHPUnit_Framework_ExpectationFailedException' );
     8        class_alias( 'PHPUnit\Framework\Error\Deprecated', 'PHPUnit_Framework_Error_Deprecated' );
    89        class_alias( 'PHPUnit\Framework\Error\Notice', 'PHPUnit_Framework_Error_Notice' );
    910        class_alias( 'PHPUnit\Framework\Error\Warning', 'PHPUnit_Framework_Error_Warning' );
    1011        class_alias( 'PHPUnit\Framework\Test', 'PHPUnit_Framework_Test' );
  • tests/phpunit/tests/compat.php

    diff --git a/tests/phpunit/tests/compat.php b/tests/phpunit/tests/compat.php
    index dd6e06c0af..a8b14ee42c 100644
    a b EOT; 
    180180        }
    181181
    182182        /**
    183          * @expectedException PHPUnit_Framework_Error_Notice
     183         * @expectedException PHPUnit_Framework_Error_Deprecated
    184184         */
    185185        function test_json_encode_decode() {
    186186                require_once( ABSPATH . WPINC . '/class-json.php' );