[wp-trac] [WordPress Trac] #63962: PHP 8.5: Fix deprecation notices for __sleep and __wakeup magic methods

WordPress Trac noreply at wordpress.org
Fri Sep 12 10:20:27 UTC 2025


#63962: PHP 8.5: Fix deprecation notices for __sleep and __wakeup magic methods
-------------------------------+-------------------------------
 Reporter:  TobiasBg           |      Owner:  (none)
     Type:  defect (bug)       |     Status:  new
 Priority:  normal             |  Milestone:  6.9
Component:  General            |    Version:
 Severity:  normal             |   Keywords:  needs-patch php85
  Focuses:  php-compatibility  |
-------------------------------+-------------------------------
 Parent ticket for all things PHP 8.5: #63061

 ----

 PHP 8.5 deprecates the magic methods `__sleep` and `__wakeup`:
 https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_the_sleep_and_wakeup_magic_methods

 This currently causes warnings like "Deprecated: The `__sleep()`
 serialization magic method has been deprecated. Implement `__serialize()`
 instead (or in addition, if support for old PHP versions is necessary)".

 WordPress doesn't seem to be using `__sleep` but has several `__wakeup`
 methods, in Core files (in Block management classes and the HTML API) and
 in (semi-)external libraries (Requests, sodium-compat).

 Using `__serialize` and `__unserialize` is recommended as a replacement.

 These have been introduced in PHP 7.4, so for PHP < 7.4, `__sleep` and
 `__wakeup` need to be kept.
 Fortunately, per
 [https://www.php.net/manual/en/language.oop5.magic.php#language.oop5.magic.serialize
 the docs], it's fine to have both present, which then also won't trigger
 the deprecation notices.

 Thus, the logic of `__sleep` and `__wakeup` methods should be moved to
 `__serialize` and `__unserialize`. As long as PHP < 7.4 is supported,
 `__sleep` and `__wakeup` methods should then be (re-)added as wrappers.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/63962>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list