Method %s::%s() cannot declare a return type¶
Description¶
There can be no return type for certain methods, such as the constructor and the desctructor.
The constructor is called while creating a new instance of an object, but it doesn’t return the object itself.This is the case even if $this is available in the method.
The destructor is called while destroying an instance, and shall not return anything.
Theses methods must remain without a return type: not void
, not mixed
, not never
, or anthing else.
Example¶
<?php
class X {
function __construct() : int { }
function __destruct() : string { }
}
?>
Literal Examples¶
Method X::__construct() cannot declare a return type
Method X::__destruct() cannot declare a return type
Solutions¶
Remove the return type of the method.