Php object-oriented notes (1)

Source: Internet
Author: User
1. What are the keywords used for class definition in php? Class ?, Generally, the class name uses the upper-case classPeople {} 2. The attribute (data status) of the object is a variable defined in the class. You can use publicprivateprotect to declare the access permission. classPeople {public? $ Sex ;?? Public, can be freely accessed inside and outside the class pr

1. What are the keywords used for class definition in php? Class ?, General class names use uppercase class People {} 2. the attribute (data status) of an object is a variable defined in the class. You can use public private protect to declare the access permission. class People {public? $ Sex ;? ? // Public, pr can be accessed inside and outside the class at will

1. What are the keywords used for class definition in php? Class ?, General class names use uppercase letters

class People{}

2. the attribute (data status) of the object is a variable defined in the class, and the access permission can be declared through public private protect;

Class People {public? $ Sex ;? ? // Public, which can be freely accessed inside and outside the class. protect $ name = 'libi'; // protected, private $ age can only be accessed inside the class and in the subclass ;? ? //? Private, accessible only within the class}

You can use the-> symbol to call the attributes of an object ;? Use $ this-> to call the attributes of this object in the method.

3. The method in php5 uses function to define the method. The method name is generally lowercase;

4. Will the constructor automatically call this function during Object Instantiation for initialization? _ Construct ()? ? Parameters passed to the class when the sample object is passed to the constructor; explicit constructor can be used;

5. destructor: this function is executed when the object becomes garbage (no variable points to this object) or when a php thread ends and all objects in the current program are destroyed, is it the opposite of the constructor? _ Destruct ()
Unset () is used to destroy the variable pointing to the object;

6. What is the key word extends for class inheritance? The inherited class is called a subclass, And the inherited class is called a parent class or a superclass;

Use the keyword parent: In the subclass to call the method of the parent class.

7. Method Rewriting: when the method inherited from the parent class cannot meet the requirements of the subclass, You can override the method;

During method rewriting, the method to be rewritten must have the same method name. php5 does not limit the data type and parameters, and the return value;

The override method of the subclass cannot have more strict access than the parent class (the access permission of the override method of the subclass can only be loose than that of the parent class );

8. Overload )? PHP 5 does not support overloading.

Original article address: php object-oriented note (1). Thank you for sharing it.

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.