PHP static method call questions, ask Daniel to answer

Source: Internet
Author: User
PHP static method call problem, ask Daniel to answer


Class Cat {
}
Class Hypnotic_cat extends Cat {
Constructor
function Hypnotic_cat () {
}
This function must is called statically
public static function Hypnotize () {
Echo ("The cat was hypnotized.");
Return
}
}
Hypnotize All Cats
Hypnotic_cat::hypnotize ();
$hypnotic _cat = new Hypnotic_cat ();
Does Nothing
$hypnotic _cat->hypnotize ();
?>


Why is this call or can it be a result? The static method is not only used:: To invoke it?
------Solution--------------------
Who told you not to? Of course you can!

Just what you need to notice is that the static method cannot be used $this

------Solution--------------------
Can be used this way, but detours, is generally hypnotic_cat::hypnotize ();
------Solution--------------------
Citation:
who told you not to? Of course you can!

Just what you need to notice is that the static method cannot be used $this

To add, you'd better not show up in a static method.
As for calling methods, this is very flexible.
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.