Call to %s method %s::%s() from %s%s¶
Description¶
A private
method shall only be called from within its own class. It cannot be called from another class, or from the global space. In particular, the method cannot be called directly, or indirectly: for example, new X
indirectly calls the __construct
method.
A protected
method shall only be called from within its own class, or any of it parent or children. It cannot be called from another non-related class, or from the global space. In particular, the method cannot be called directly, or indirectly: for example, new X
indirectly calls the __construct
method.
A public
method may be called from anywhere in the code.
Example¶
<?php
class X {
//This is also the case with proctected __construct
private function __construct() {}
static public function factory() {
return new X();
}
}
//This is not possible
$x = new X();
?>
Literal Examples¶
Call to private method X::__construct() from global scope
Solutions¶
Check that the call to the method, and the visibility of the method are compatible.
In previous PHP versions, this error message used to be Call to %s %s::%s() from invalid.