General: Continuing to work towards a passing PHP Compatibility scan.

This is a final pass to fix PHP compatibiilty issues in the codebase with code changes or adding `phpcs:ignore` comments.

With this change, all PHP compatibility warnings and errors without specific tickets have been addressed (see #49810 and #41750).

Props desrosj, johnbillion, jrf.
See #49922.

git-svn-id: https://develop.svn.wordpress.org/trunk@47902 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonathan Desrosiers 2020-06-03 17:38:56 +00:00
parent 2da8918f1a
commit dfccba8d55
11 changed files with 16 additions and 22 deletions

View File

@ -74,7 +74,7 @@
</rule>
<!-- Whitelist the WP DB Class for use of `mysql_` extension in PHP < 7.0. -->
<rule ref="PHPCompatibility.Extensions.RemovedExtensions">
<rule ref="PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved">
<exclude-pattern>/src/wp-includes/wp-db\.php</exclude-pattern>
</rule>
</ruleset>

View File

@ -899,7 +899,7 @@ class ftp_base {
$mod_sockets = extension_loaded( 'sockets' );
if ( ! $mod_sockets && function_exists( 'dl' ) && is_callable( 'dl' ) ) {
$prefix = ( PHP_SHLIB_SUFFIX == 'dll' ) ? 'php_' : '';
@dl( $prefix . 'sockets.' . PHP_SHLIB_SUFFIX );
@dl( $prefix . 'sockets.' . PHP_SHLIB_SUFFIX ); // phpcs:ignore PHPCompatibility.FunctionUse.RemovedFunctions.dlDeprecated
$mod_sockets = extension_loaded( 'sockets' );
}

View File

@ -114,7 +114,7 @@ class getid3_quicktime extends getid3_handler
foreach ($info['quicktime']['comments']['location.ISO6709'] as $ISO6709string) {
$ISO6709parsed = array('latitude'=>false, 'longitude'=>false, 'altitude'=>false);
if (preg_match('#^([\\+\\-])([0-9]{2}|[0-9]{4}|[0-9]{6})(\\.[0-9]+)?([\\+\\-])([0-9]{3}|[0-9]{5}|[0-9]{7})(\\.[0-9]+)?(([\\+\\-])([0-9]{3}|[0-9]{5}|[0-9]{7})(\\.[0-9]+)?)?/$#', $ISO6709string, $matches)) {
@list($dummy, $lat_sign, $lat_deg, $lat_deg_dec, $lon_sign, $lon_deg, $lon_deg_dec, $dummy, $alt_sign, $alt_deg, $alt_deg_dec) = $matches;
@list($dummy, $lat_sign, $lat_deg, $lat_deg_dec, $lon_sign, $lon_deg, $lon_deg_dec, $dummy, $alt_sign, $alt_deg, $alt_deg_dec) = $matches; // phpcs:ignore PHPCompatibility.Lists.AssignmentOrder.Affected
if (strlen($lat_deg) == 2) { // [+-]DD.D
$ISO6709parsed['latitude'] = (($lat_sign == '-') ? -1 : 1) * floatval(ltrim($lat_deg, '0').$lat_deg_dec);

View File

@ -290,8 +290,8 @@ function map_meta_cap( $cap, $user_id, ...$args ) {
case 'edit_user_meta':
case 'delete_user_meta':
case 'add_user_meta':
list( $_, $object_type, $_ ) = explode( '_', $cap );
$object_id = (int) $args[0];
$object_type = explode( '_', $cap )[1];
$object_id = (int) $args[0];
$object_subtype = get_object_subtype( $object_type, $object_id );

View File

@ -187,7 +187,8 @@ class Requests {
// Don't search for a transport if it's already been done for these $capabilities
if (isset(self::$transport[$cap_string]) && self::$transport[$cap_string] !== null) {
return new self::$transport[$cap_string]();
$class = self::$transport[$cap_string];
return new $class();
}
// @codeCoverageIgnoreEnd
@ -214,7 +215,8 @@ class Requests {
throw new Requests_Exception('No working transports found', 'notransport', self::$transports);
}
return new self::$transport[$cap_string]();
$class = self::$transport[$cap_string];
return new $class();
}
/**#@+

View File

@ -3165,7 +3165,7 @@ class SimplePie
}
$class = get_class($this);
$trace = debug_backtrace();
$trace = debug_backtrace(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
$file = $trace[0]['file'];
$line = $trace[0]['line'];
trigger_error("Call to undefined method $class::$method() in $file on line $line", E_USER_ERROR);

View File

@ -402,7 +402,7 @@ function wp_clear_scheduled_hook( $hook, $args = array() ) {
// Previously, this function took the arguments as discrete vars rather than an array like the rest of the API.
if ( ! is_array( $args ) ) {
_deprecated_argument( __FUNCTION__, '3.0.0', __( 'This argument has changed to an array to match the behavior of the other cron functions.' ) );
$args = array_slice( func_get_args(), 1 );
$args = array_slice( func_get_args(), 1 ); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
}
/**

View File

@ -6627,7 +6627,7 @@ function mbstring_binary_safe_encoding( $reset = false ) {
static $overloaded = null;
if ( is_null( $overloaded ) ) {
$overloaded = function_exists( 'mb_internal_encoding' ) && ( ini_get( 'mbstring.func_overload' ) & 2 );
$overloaded = function_exists( 'mb_internal_encoding' ) && ( ini_get( 'mbstring.func_overload' ) & 2 ); // phpcs:ignore PHPCompatibility.IniDirectives.RemovedIniDirectives.mbstring_func_overloadDeprecated
}
if ( false === $overloaded ) {

View File

@ -231,7 +231,7 @@ function apply_filters_ref_array( $tag, $args ) {
// Do 'all' actions first.
if ( isset( $wp_filter['all'] ) ) {
$wp_current_filter[] = $tag;
$all_args = func_get_args();
$all_args = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
_wp_call_all_hook( $all_args );
}
@ -453,7 +453,7 @@ function do_action( $tag, ...$arg ) {
// Do 'all' actions first.
if ( isset( $wp_filter['all'] ) ) {
$wp_current_filter[] = $tag;
$all_args = func_get_args();
$all_args = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
_wp_call_all_hook( $all_args );
}
@ -526,7 +526,7 @@ function do_action_ref_array( $tag, $args ) {
// Do 'all' actions first.
if ( isset( $wp_filter['all'] ) ) {
$wp_current_filter[] = $tag;
$all_args = func_get_args();
$all_args = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
_wp_call_all_hook( $all_args );
}

View File

@ -18,7 +18,7 @@ if ( ! class_exists( 'POMO_Reader', false ) ) :
* PHP5 constructor.
*/
function __construct() {
$this->is_overloaded = ( ( ini_get( 'mbstring.func_overload' ) & 2 ) != 0 ) && function_exists( 'mb_substr' );
$this->is_overloaded = ( ( ini_get( 'mbstring.func_overload' ) & 2 ) != 0 ) && function_exists( 'mb_substr' ); // phpcs:ignore PHPCompatibility.IniDirectives.RemovedIniDirectives.mbstring_func_overloadDeprecated
$this->_pos = 0;
}

View File

@ -385,10 +385,6 @@ class MagpieRSS {
}
function error( $errormsg, $lvl = E_USER_WARNING ) {
// append PHP's error message if track_errors enabled
if ( isset($php_errormsg) ) {
$errormsg .= " ($php_errormsg)";
}
if ( MAGPIE_DEBUG ) {
trigger_error( $errormsg, $lvl);
} else {
@ -821,10 +817,6 @@ class RSSCache {
Purpose: register error
\*=======================================================================*/
function error ($errormsg, $lvl=E_USER_WARNING) {
// append PHP's error message if track_errors enabled
if ( isset($php_errormsg) ) {
$errormsg .= " ($php_errormsg)";
}
$this->ERROR = $errormsg;
if ( MAGPIE_DEBUG ) {
trigger_error( $errormsg, $lvl);