I'm learning Laravel and the way I learn a new framework is going deep and found how/why magic happened in that. So I learn facades and love them and wanna found how Laravel do the magic and found a way to have similar feature is __callStatic
magic method. and here is my code :
class Facade {
public static function __callStatic($method,$args){
$instance = static::getFacade();
return call_user_func_array([$instance, $method], $args);
}
}
class DB extends Facade {
public static function getFacade(){
return new self();
}
public function init(){
echo 'INIT DB';
}
}
DB::init();
the code has a right output but I get this error:
Non-static method DB::init() should not be called statically :21
I don't understand why I got this and also Why I don't get this error in Laravel application that does this.
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Je7r1z
via IFTTT
Aucun commentaire:
Enregistrer un commentaire