%s::%s(): Return type must be %s when declared¶
Description¶
The magic methods __sleep and __serialize may be left without a return type. By construction, PHP uses array for them.
So, when a return type is written in the source, for these methods, it must be array.
Here is the list of compulsory return types:
__destruct() :
void__construct() :
void__unserialize() :
void__unset() :
void__set() :
void__serialize() :
array__isset() :
bool__toString() :
string.
Example¶
<?php
class X {
function __construct() : int {}
function __sleep() : int {}
function __serialize() : int {}
function __isset() : int {}
}
?>
Literal Examples¶
X::__sleep(): Return type must be array when declared
X::__construct(): Return type must be void when declared
X::__isset(): Return type must be bool when declared
Solutions¶
Give the correct return type to the magic method.
Remove the return type of the magic method.