1
I’m trying to return an instance of the same class in static functions, for example, in the code below, works normal:
class Router
{
private $name;
public function get()
{
return $this;
}
public function name($name) {
$this->name = $name;
}
}
And to use:
$router = new Router();
$router->get()->name('string');
But when I try to static function
, nothing happens.
class Router
{
private static $name;
public static function get()
{
return self::class;
}
public static function name($name) {
self::$name = $name;
}
}
And to use:
Router::get()->name('string');
With static
return receipt:
Fatal error: Uncaught Error: Call to a Member Function name()
You don’t know what you intended to happen, you both do nothing, because that’s what these classes do. https://ideone.com/OoCL0n Anyway it doesn’t make much sense to create a code like this, it would have to explain better where you want to get.
– Maniero
@Maniero, I edited the question, see if you can understand.
– Max Fly
The question has changed completely, but the text still deals with some of the old way and has become confused, but I will answer anyway because I think I can understand despite being poorly formulated.
– Maniero