Make WordPress Core


Ignore:
Timestamp:
09/20/2019 10:33:13 PM (7 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-widget-factory.php

    r42343 r46220  
    5757
    5858        /**
    59          * Hashes an object, doing fallback of `spl_object_hash()` if not available.
    60          *
    61          * This can be eliminated in favor of straight spl_object_hash() when 5.3
    62          * is the minimum requirement for PHP.
    63          *
    64          * @since 4.6.0
    65          *
    66          * @param WP_Widget $widget Widget.
    67          * @return string Object hash.
    68          */
    69         private function hash_object( $widget ) {
    70                 if ( function_exists( 'spl_object_hash' ) ) {
    71                         return spl_object_hash( $widget );
    72                 } else {
    73                         $class_name = get_class( $widget );
    74                         $hash       = $class_name;
    75                         if ( ! isset( $widget->_wp_widget_factory_hash_id ) ) {
    76                                 if ( ! isset( $this->hashed_class_counts[ $class_name ] ) ) {
    77                                         $this->hashed_class_counts[ $class_name ] = 0;
    78                                 }
    79                                 $this->hashed_class_counts[ $class_name ] += 1;
    80                                 $widget->_wp_widget_factory_hash_id        = $this->hashed_class_counts[ $class_name ];
    81                         }
    82                         $hash .= ':' . $widget->_wp_widget_factory_hash_id;
    83                         return $hash;
    84                 }
    85         }
    86 
    87         /**
    8859         * Registers a widget subclass.
    8960         *
     
    9667        public function register( $widget ) {
    9768                if ( $widget instanceof WP_Widget ) {
    98                         $this->widgets[ $this->hash_object( $widget ) ] = $widget;
     69                        $this->widgets[ spl_object_hash( $widget ) ] = $widget;
    9970                } else {
    10071                        $this->widgets[ $widget ] = new $widget();
     
    11384        public function unregister( $widget ) {
    11485                if ( $widget instanceof WP_Widget ) {
    115                         unset( $this->widgets[ $this->hash_object( $widget ) ] );
     86                        unset( $this->widgets[ spl_object_hash( $widget ) ] );
    11687                } else {
    11788                        unset( $this->widgets[ $widget ] );
Note: See TracChangeset for help on using the changeset viewer.