For more information about php static method calls

Source: Internet
Author: User
For the php static method call question, could you please answer ;? Phpclass & nbsp; Cat & nbsp ;{} class & nbsp; Hypnotic_Cat & nbsp; extends & nbsp; Cat & nbsp ;{// & nbsp; Construc php static method call problems, please answer


class Cat {
}
class Hypnotic_Cat extends Cat {
// Constructor
function Hypnotic_Cat( ) {
}
// This function must be 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 it possible to use "->" to call or produce results? Static methods can only be called using?
------ Solution --------------------
Who told you they couldn't? Of course!

However, you must note that $ this cannot be used in static methods.

------ Solution --------------------
It can be used in this way, but it turns around. it is generally Hypnotic_Cat: hypnotize ();
------ Solution --------------------
Reference:
Who told you they couldn't? Of course!

However, you must note that $ this cannot be used in static methods.

In the static method, you 'd better not appear-> that's right.
The call method is flexible.

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.