是否可以非静态地调用静态方法?是,但是会丢失$this.您还没有得到警告,但实际上也没有理由以错误的方式来称呼它.I have a child class that extends a class with only static methods. I would like to make this child class a singleton rather than static because the original developer really wanted a singleton but used static instead (obvious because every method in the static class calls the Init() function (basically a constructor)).Most of the methods in the parent don't need to be overwritten in the child, but I would like to avoid having to write methods like this:public function Load($id){ return parent::Load($id);}when I would prefer not to overwrite the method at all and just use:$child->Load($id);Is it possible to call a static method non-statically? Is it possible to extend a static object with an instance object? I know I can try it and it will likely work (PHP is very forgiving), but I don't know if there is anything I should be concerned about. 解决方案Can you inherit static methods?YesCan you override static methods?Yes, but only as of PHP 5.3 do they work as you would expect: http://www.php.net/manual/en/language.oop5.static.php (ie. self binds to the actual class and not the class it's defined in).Is it possible to call a static method non-statically?Yes, but will lose $this. You don't get a warning (yet) but there also isn't really a reason to call it the wrong way. 这篇关于非静态调用静态方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!