简体   繁体   中英

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?

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() . Either would work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM