Skip to:
Content

BuddyPress.org

Changeset 12426


Ignore:
Timestamp:
08/08/2019 08:11:51 PM (7 years ago)
Author:
boonebgorges
Message:

Cast func_get_args() to variable early in class methods.

Since PHP 7.0, calling func_get_args() returns the current value of
the parameter, which may have been modified since the beginning of the
method. By storing the original function arguments in a variable at the
beginning of the method, we ensure that the value operated on later in
the method accurately reflects what was originally passed.

In most cases addressed by this changeset, there was no real-world
possibility that the arguments could be changed; we make this change
mostly as a best practice, and to appease the PHP compatibility linter.

Fixes #8125.

Location:
trunk/src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/classes/class-bp-activity-activity.php

    r12420 r12426  
    361361                global $wpdb;
    362362
     363                $function_args = func_get_args();
     364
    363365                // Backward compatibility with old method of passing arguments.
    364                 if ( !is_array( $args ) || func_num_args() > 1 ) {
     366                if ( !is_array( $args ) || count( $function_args ) > 1 ) {
    365367                        _deprecated_argument( __METHOD__, '1.6', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
    366368
     
    379381                        );
    380382
    381                         $args = bp_core_parse_args_array( $old_args_keys, func_get_args() );
     383                        $args = bp_core_parse_args_array( $old_args_keys, $function_args );
    382384                }
    383385
     
    14681470                global $wpdb;
    14691471
     1472                $function_args = func_get_args();
     1473
    14701474                if ( empty( $top_level_parent_id ) ) {
    14711475                        $top_level_parent_id = $activity_id;
     
    15151519                         * @param array                $func_args Array of the method's argument list.
    15161520                         */
    1517                         if ( apply_filters( 'bp_use_legacy_activity_query', false, __METHOD__, func_get_args() ) ) {
     1521                        if ( apply_filters( 'bp_use_legacy_activity_query', false, __METHOD__, $function_args ) ) {
    15181522
    15191523                                /**
  • trunk/src/bp-activity/classes/class-bp-activity-template.php

    r11764 r12426  
    140140                $bp = buddypress();
    141141
     142                $function_args = func_get_args();
     143
    142144                // Backward compatibility with old method of passing arguments.
    143                 if ( !is_array( $args ) || func_num_args() > 1 ) {
     145                if ( !is_array( $args ) || count( $function_args ) > 1 ) {
    144146                        _deprecated_argument( __METHOD__, '1.6', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
    145147
     
    160162                        );
    161163
    162                         $args = bp_core_parse_args_array( $old_args_keys, func_get_args() );
     164                        $args = bp_core_parse_args_array( $old_args_keys, $function_args );
    163165                }
    164166
  • trunk/src/bp-groups/bp-groups-functions.php

    r12405 r12426  
    240240 */
    241241function groups_edit_base_group_details( $args = array() ) {
     242        $function_args = func_get_args();
    242243
    243244        // Backward compatibility with old method of passing arguments.
    244         if ( ! is_array( $args ) || func_num_args() > 1 ) {
     245        if ( ! is_array( $args ) || count( $function_args ) > 1 ) {
    245246                _deprecated_argument( __METHOD__, '2.9.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
    246247
     
    252253                );
    253254
    254                 $args = bp_core_parse_args_array( $old_args_keys, func_get_args() );
     255                $args = bp_core_parse_args_array( $old_args_keys, $function_args );
    255256        }
    256257
     
    690691 */
    691692function groups_get_group_members( $args = array() ) {
     693        $function_args = func_get_args();
    692694
    693695        // Backward compatibility with old method of passing arguments.
    694         if ( ! is_array( $args ) || func_num_args() > 1 ) {
     696        if ( ! is_array( $args ) || count( $function_args ) > 1 ) {
    695697                _deprecated_argument( __METHOD__, '2.0.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
    696698
     
    705707                );
    706708
    707                 $args = bp_core_parse_args_array( $old_args_keys, func_get_args() );
     709                $args = bp_core_parse_args_array( $old_args_keys, $function_args );
    708710        }
    709711
     
    721723
    722724        // For legacy users. Use of BP_Groups_Member::get_all_for_group() is deprecated.
    723         if ( apply_filters( 'bp_use_legacy_group_member_query', false, __FUNCTION__, func_get_args() ) ) {
     725        if ( apply_filters( 'bp_use_legacy_group_member_query', false, __FUNCTION__, $function_args ) ) {
    724726                $retval = BP_Groups_Member::get_all_for_group( $r['group_id'], $r['per_page'], $r['page'], $r['exclude_admins_mods'], $r['exclude_banned'], $r['exclude'] );
    725727        } else {
  • trunk/src/bp-groups/classes/class-bp-groups-group-members-template.php

    r11805 r12426  
    9494         */
    9595        public function __construct( $args = array() ) {
     96                $function_args = func_get_args();
    9697
    9798                // Backward compatibility with old method of passing arguments.
    98                 if ( ! is_array( $args ) || func_num_args() > 1 ) {
     99                if ( ! is_array( $args ) || count( $function_args ) > 1 ) {
    99100                        _deprecated_argument( __METHOD__, '2.0.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
    100101
     
    109110                        );
    110111
    111                         $args = bp_core_parse_args_array( $old_args_keys, func_get_args() );
     112                        $args = bp_core_parse_args_array( $old_args_keys, $function_args );
    112113                }
    113114
  • trunk/src/bp-groups/classes/class-bp-groups-group.php

    r12326 r12426  
    10471047                global $wpdb;
    10481048
     1049                $function_args = func_get_args();
     1050
    10491051                // Backward compatibility with old method of passing arguments.
    1050                 if ( ! is_array( $args ) || func_num_args() > 1 ) {
     1052                if ( ! is_array( $args ) || count( $function_args ) > 1 ) {
    10511053                        _deprecated_argument( __METHOD__, '1.7', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
    10521054
     
    10631065                        );
    10641066
    1065                         $args = bp_core_parse_args_array( $old_args_keys, func_get_args() );
     1067                        $args = bp_core_parse_args_array( $old_args_keys, $function_args );
    10661068                }
    10671069
  • trunk/src/bp-groups/classes/class-bp-groups-invite-template.php

    r11805 r12426  
    7979         */
    8080        public function __construct( $args = array() ) {
     81                $function_args = func_get_args();
    8182
    8283                // Backward compatibility with old method of passing arguments.
    83                 if ( ! is_array( $args ) || func_num_args() > 1 ) {
     84                if ( ! is_array( $args ) || count( $function_args ) > 1 ) {
    8485                        _deprecated_argument( __METHOD__, '2.0.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
    8586
     
    8990                        );
    9091
    91                         $args = bp_core_parse_args_array( $old_args_keys, func_get_args() );
     92                        $args = bp_core_parse_args_array( $old_args_keys, $function_args );
    9293                }
    9394
  • trunk/src/bp-groups/classes/class-bp-groups-membership-requests-template.php

    r11805 r12426  
    8686         */
    8787        public function __construct( $args = array() ) {
     88                $function_args = func_get_args();
    8889
    8990                // Backward compatibility with old method of passing arguments.
    90                 if ( ! is_array( $args ) || func_num_args() > 1 ) {
     91                if ( ! is_array( $args ) || count( $function_args ) > 1 ) {
    9192                        _deprecated_argument( __METHOD__, '2.0.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
    9293
     
    9798                        );
    9899
    99                         $args = bp_core_parse_args_array( $old_args_keys, func_get_args() );
     100                        $args = bp_core_parse_args_array( $old_args_keys, $function_args );
    100101                }
    101102
  • trunk/src/bp-groups/classes/class-bp-groups-template.php

    r11805 r12426  
    129129         */
    130130        function __construct( $args = array() ){
     131                $function_args = func_get_args();
    131132
    132133                // Backward compatibility with old method of passing arguments.
    133                 if ( ! is_array( $args ) || func_num_args() > 1 ) {
     134                if ( ! is_array( $args ) || count( $function_args ) > 1 ) {
    134135                        _deprecated_argument( __METHOD__, '1.7', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
    135136
     
    149150                        );
    150151
    151                         $args = bp_core_parse_args_array( $old_args_keys, func_get_args() );
     152                        $args = bp_core_parse_args_array( $old_args_keys, $function_args );
    152153                }
    153154
  • trunk/src/bp-messages/classes/class-bp-messages-box-template.php

    r11363 r12426  
    108108         */
    109109        public function __construct( $args = array() ) {
     110                $function_args = func_get_args();
    110111
    111112                // Backward compatibility with old method of passing arguments.
    112                 if ( ! is_array( $args ) || func_num_args() > 1 ) {
     113                if ( ! is_array( $args ) || count( $function_args ) > 1 ) {
    113114                        _deprecated_argument( __METHOD__, '2.2.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
    114115
     
    123124                        );
    124125
    125                         $args = bp_core_parse_args_array( $old_args_keys, func_get_args() );
     126                        $args = bp_core_parse_args_array( $old_args_keys, $function_args );
    126127                }
    127128
  • trunk/src/bp-messages/classes/class-bp-messages-thread.php

    r11578 r12426  
    446446                global $wpdb;
    447447
     448                $function_args = func_get_args();
     449
    448450                // Backward compatibility with old method of passing arguments.
    449                 if ( ! is_array( $args ) || func_num_args() > 1 ) {
     451                if ( ! is_array( $args ) || count( $function_args ) > 1 ) {
    450452                        _deprecated_argument( __METHOD__, '2.2.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
    451453
     
    459461                        );
    460462
    461                         $args = bp_core_parse_args_array( $old_args_keys, func_get_args() );
     463                        $args = bp_core_parse_args_array( $old_args_keys, $function_args );
    462464                }
    463465
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-data-template.php

    r11363 r12426  
    124124         */
    125125        public function __construct( $args = '' ) {
     126                $function_args = func_get_args();
    126127
    127128                // Backward compatibility with old method of passing arguments.
    128                 if ( ! is_array( $args ) || func_num_args() > 1 ) {
     129                if ( ! is_array( $args ) || count( $function_args ) > 1 ) {
    129130                        _deprecated_argument( __METHOD__, '2.3.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
    130131
     
    142143                        );
    143144
    144                         $args = bp_core_parse_args_array( $old_args_keys, func_get_args() );
     145                        $args = bp_core_parse_args_array( $old_args_keys, $function_args );
    145146                }
    146147
Note: See TracChangeset for help on using the changeset viewer.