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.

git-svn-id: https://develop.svn.wordpress.org/trunk@46220 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2019-09-20 22:33:13 +00:00
parent 3a49864e41
commit 4ee97a4ac3
2 changed files with 3 additions and 48 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;
}
} elseif ( is_string( $function[0] ) ) {
// Static Calling
return $function[0] . '::' . $function[1];