Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

The __sleep() serialization magic method has been deprecated.

Description

Class serialization in PHP has had multiple mechanism introduced to control its behaviour by userland. Initially with the __sleep() and __wakeup() magic methods, then with the Serializable interface and finally with __serialize() and __unserialize().

In the end, the __serialize and __unserialize methods must be used, instead of __sleep and __wakeup.

Example

<?php

class X {
    function __sleep() {}
}

?>

Alternatives

  • Rename the method to __serialize.

Changed Behavior

This error may appear following an evolution in behavior, in previous versions. See