[英]Calling a parent classes method vs. calling a static method
To call a parent class (it has been instantiated) method I use 调用父类(已实例化)的方法
parent_class::method(); //tested it works
to call a method with in the instantiated class I am in I use 在我使用的实例化类中调用方法
$this->method(); //tested it works
However if I call a static method from any class I use 但是,如果我从任何类中调用静态方法,
parent_class::static_method(); //tested it works
I guess this makes since bc there is only one copy of a method per class, whether it is instantiated or not? 我猜想这使得既然bc每个类只有一个方法的副本,而无论它是否被实例化?
Can some one validate or provide insight to this. 有人可以对此进行验证或提供见解吗? I just want to verify that the call method is the same for both static methods from any class and calls to a parent classes method. 我只想验证任何类的静态方法和父类方法的调用的调用方法是否相同。
Seems a bit strange. 似乎有点奇怪。
The syntax is correct. 语法正确。 Not exactly sure what your question is. 不完全确定您的问题是什么。 If you wanted to call a static method defined in the child from within the child, you could use self::static_method()
or $this->static_method()
. 如果要从子级中调用子级中定义的静态方法,可以使用self::static_method()
或$this->static_method()
。 Either would work. 无论哪种都行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.