Make WordPress Core


Ignore:
Timestamp:
09/23/2025 07:26:03 PM (12 months ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Address __sleep() and __wakeup() deprecations in PHP 8.5.

PHP 8.5 deprecates the __sleep() and __wakeup() magic methods in favor of __serialize() and __unserialize():

Deprecated: The __wakeup() serialization magic method has been deprecated. Implement __unserialize() instead (or in addition, if support for old PHP versions is necessary)

For PHP < 7.4 compatibility, __sleep() and __wakeup() need to be kept for the time being.

This commit moves the logic of __wakeup() methods in core to __unserialize(), and turns the former into wrappers. WordPress core does not use __sleep() methods, so these are the only changes required.

Reference: PHP RFC: Deprecations for PHP 8.5: Deprecate the __sleep() and __wakeup() magic methods.

Follow-up to [56835], [60787], [60795].

Props TobiasBg, tusharbharti, swissspidy, dmsnell, SergeyBiryukov.
Fixes #63962. See #63061.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-block-bindings-registry.php

    r59080 r60796  
    258258
    259259        /**
    260          * Wakeup magic method.
    261          *
    262          * @since 6.5.0
    263          */
    264         public function __wakeup() {
     260         * Unserialize magic method.
     261         *
     262         * @since 6.9.0
     263         *
     264         * @param array $data Data to unserialize.
     265         */
     266        public function __unserialize( $data ) { // phpcs:ignore PHPCompatibility.FunctionNameRestrictions.NewMagicMethods.__unserializeFound
    265267                if ( ! $this->sources ) {
    266268                        return;
     
    277279
    278280        /**
     281         * Wakeup magic method.
     282         *
     283         * @since 6.5.0
     284         */
     285        public function __wakeup() {
     286                $this->__unserialize( array() );
     287        }
     288
     289        /**
    279290         * Utility method to retrieve the main instance of the class.
    280291         *
Note: See TracChangeset for help on using the changeset viewer.