PHP Learning Notes (4)

Source: Internet
Author: User

Declaring a class property or method as static can be accessed directly without instantiating the class. Static properties cannot be accessed through an object that a class has instantiated (but static methods can).

PHP 5 supports abstract classes and abstract methods. A class that is defined as abstract cannot be instantiated

Using interfaces (interface), you can specify which methods a class must implement, but you do not need to define the specifics of these methods.

The __tostring () method is used to respond to a class when it is treated as a string.

The __invoke () method is called automatically when an attempt is made to invoke an object in a way that invokes a function .

The use of late static bindings?

Class A {
public static function foo () {
Static::who ();
}

public static function who () {
echo __class__. " \ n ";
}
}

Class B extends A {
public static function test () {
A::foo (); This is the field represented by the class name, and the latter two are expressed in relation to the parent self. Visible, the class name can be used to control the domain, and the relative domain is all later bound.
Parent::foo ();
Self::foo ();
}

public static function who () {
echo __class__. " \ n ";
}
}
Class C extends B {
public static function who () {
echo __class__. " \ n ";
}
}

C::test ();

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.