Code Modernization: Remove workarounds for spl_object_hash().

The `spl_object_hash()` function was introduced in PHP 5.2.0. As of PHP 5.3, the PHP SPL extension can no longer be disabled, so these workarounds are no longer needed.

Props jrf.
See #48074.
Built from https://develop.svn.wordpress.org/trunk@46220


git-svn-id: http://core.svn.wordpress.org/trunk@46032 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2019-09-20 22:34:57 +00:00
parent c2314fc44b
commit fe82a615a9
3 changed files with 4 additions and 49 deletions

View File

@ -55,35 +55,6 @@ class WP_Widget_Factory {
*/
private $hashed_class_counts = array();
/**
* Hashes an object, doing fallback of `spl_object_hash()` if not available.
*
* This can be eliminated in favor of straight spl_object_hash() when 5.3
* is the minimum requirement for PHP.
*
* @since 4.6.0
*
* @param WP_Widget $widget Widget.
* @return string Object hash.
*/
private function hash_object( $widget ) {
if ( function_exists( 'spl_object_hash' ) ) {
return spl_object_hash( $widget );
} else {
$class_name = get_class( $widget );
$hash = $class_name;
if ( ! isset( $widget->_wp_widget_factory_hash_id ) ) {
if ( ! isset( $this->hashed_class_counts[ $class_name ] ) ) {
$this->hashed_class_counts[ $class_name ] = 0;
}
$this->hashed_class_counts[ $class_name ] += 1;
$widget->_wp_widget_factory_hash_id = $this->hashed_class_counts[ $class_name ];
}
$hash .= ':' . $widget->_wp_widget_factory_hash_id;
return $hash;
}
}
/**
* Registers a widget subclass.
*
@ -95,7 +66,7 @@ class WP_Widget_Factory {
*/
public function register( $widget ) {
if ( $widget instanceof WP_Widget ) {
$this->widgets[ $this->hash_object( $widget ) ] = $widget;
$this->widgets[ spl_object_hash( $widget ) ] = $widget;
} else {
$this->widgets[ $widget ] = new $widget();
}
@ -112,7 +83,7 @@ class WP_Widget_Factory {
*/
public function unregister( $widget ) {
if ( $widget instanceof WP_Widget ) {
unset( $this->widgets[ $this->hash_object( $widget ) ] );
unset( $this->widgets[ spl_object_hash( $widget ) ] );
} else {
unset( $this->widgets[ $widget ] );
}

View File

@ -925,23 +925,7 @@ function _wp_filter_build_unique_id( $tag, $function, $priority ) {
if ( is_object( $function[0] ) ) {
// Object Class Calling
if ( function_exists( 'spl_object_hash' ) ) {
return spl_object_hash( $function[0] ) . $function[1];
} else {
$obj_idx = get_class( $function[0] ) . $function[1];
if ( ! isset( $function[0]->wp_filter_id ) ) {
if ( false === $priority ) {
return false;
}
$obj_idx .= isset( $wp_filter[ $tag ][ $priority ] ) ? count( (array) $wp_filter[ $tag ][ $priority ] ) : $filter_id_count;
$function[0]->wp_filter_id = $filter_id_count;
++$filter_id_count;
} else {
$obj_idx .= $function[0]->wp_filter_id;
}
return $obj_idx;
}
return spl_object_hash( $function[0] ) . $function[1];
} elseif ( is_string( $function[0] ) ) {
// Static Calling
return $function[0] . '::' . $function[1];

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.3-alpha-46219';
$wp_version = '5.3-alpha-46220';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.