Make WordPress Core

Changeset 44569


Ignore:
Timestamp:
01/12/2019 03:19:23 AM (6 years ago)
Author:
pento
Message:

Coding Standards: Extract extract() from the codebase.

Of the last four instances of extract() occurring, three of them are removed by this commit, and the fourth is appropriately documented.

See #45934.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentyeleven/inc/widgets.php

    r43571 r44569  
    6969
    7070        ob_start();
    71         extract( $args, EXTR_SKIP );
    7271
    7372        /** This filter is documented in wp-includes/default-widgets.php */
  • trunk/src/wp-includes/template.php

    r42678 r44569  
    685685
    686686    if ( is_array( $wp_query->query_vars ) ) {
     687        /*
     688         * This use of extract() cannot be removed. There are many possible ways that
     689         * templates could depend on variables that it creates existing, and no way to
     690         * detect and deprecate it.
     691         *
     692         * Passing the EXTR_SKIP flag is the safest option, ensuring globals and
     693         * function variables cannot be overwritten.
     694         */
     695        // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
    687696        extract( $wp_query->query_vars, EXTR_SKIP );
    688697    }
  • trunk/tests/phpunit/tests/post/output.php

    r43571 r44569  
    3030
    3131    function _shortcode_paragraph( $atts, $content ) {
    32         extract(
    33             shortcode_atts(
    34                 array(
    35                     'class' => 'graf',
    36                 ),
    37                 $atts
    38             )
     32        $processed_atts = shortcode_atts(
     33            array(
     34                'class' => 'graf',
     35            ),
     36            $atts
    3937        );
    40         return "<p class='$class'>$content</p>\n";
     38
     39        return "<p class='{$processed_atts['class']}'>$content</p>\n";
    4140    }
    4241
  • trunk/tests/phpunit/tests/shortcode.php

    r44136 r44569  
    4444    // [bartag foo="bar"]
    4545    function _shortcode_bartag( $atts ) {
    46         extract(
    47             shortcode_atts(
    48                 array(
    49                     'foo' => 'no foo',
    50                     'baz' => 'default baz',
    51                 ),
    52                 $atts,
    53                 'bartag'
    54             )
    55         );
    56 
    57         return "foo = {$foo}";
     46        $processed_atts = shortcode_atts(
     47            array(
     48                'foo' => 'no foo',
     49                'baz' => 'default baz',
     50            ),
     51            $atts,
     52            'bartag'
     53        );
     54
     55        return "foo = {$processed_atts['foo']}";
    5856    }
    5957
Note: See TracChangeset for help on using the changeset viewer.