__sleep should return an array only containing the names of instance-variables to serialize.
Description
The return type of __sleep is actually array, even when it is not mentioned. Any other returned value generate this error.
Example
<?php
class X {
function __sleep() {
return 1;
}
}
serialize(new X);
?>
Alternatives
- Return an array from __sleep.
- Add the return type
arrayand return an array from __sleep. - Remove the __sleep() method.
Related error messages
In more recent PHP versions, this error message is now :ref:%s::__sleep()-should-return-an-array-only-containing-the-names-of-instance-variables-to-serialize.