Method %s::%s() cannot be static¶
Description¶
Some PHP special methods cannot be static. This is the case of all the PHP magic methods, such as the constructor __construct
, the destructor __destruct
, and all the others: __call()
, __callStatic()
, __get()
, __set()
, __isset()
, __unset()
, __sleep()
, __wakeup()
, __serialize()
, __unserialize()
, __toString()
, __invoke()
, __set_state()
, __clone()
and __debugInfo()
.
Example¶
<?php
class X {
static function __construct() {}
}
?>
Literal Examples¶
Method x::__construct() cannot be static
Solutions¶
Make a static method that can call the method that would be static. Be aware, this will require the building of an object, as a static method does not set
$this
.