Php learning note class declaration and object instantiation _ PHP Tutorial

Source: Internet
Author: User
Php learning note class declaration and object instantiation. Copy the code as follows :? Php * class declaration * 1. what are you developing and are you sure you want to write? * 2. the members in the class must belong to this class * [modifier class keywords] class name { The code is as follows:


/* Class declaration
* 1. what are you developing and are you sure you want to write?
* 2. the members in the class must belong to this class.
* [Modifier class keywords] class name {
* Member attributes:
* Member method:
*}
* 3. when declaring a member attribute in a class, there must be a modifier first. when you are not sure which word to use, use var or public
* Only one class is saved in a file. the file name contains the class name. File: class name. class. php
* Write the class name:
* Variable: aaaBbbCcc
* Function: aaaBbbCcc
* Constant: AAABBBCCC
* Class name: AaaBbbCcc
* 4. member attributes in the class. if multiple objects have different attribute values when they are created, do not directly give the initial values.
*
*
* Instantiate objects through classes
* 1. create an object with the new class name, which is the object of the created class.
* $ Object reference = new class name;
* 2. if there is a new keyword that is used to create an object, creating an object is to allocate a space in the memory.
*
* Only objects are stored in the same bucket.
*
* Object functions
*
* Allocate objects in memory
*
* Object usage
* Members of an object must be accessed through object references.
* Object> Member
*
* Object> member attributes
* Object> Member method
*
*
*
*/
// Class declaration (telephone class)
Class Phone {
// Declare attributes
Var $ pinPai;
Var $ color;
Var $ batteryCapacity;
Var $ screenSize;
// Member method
Function call (){
}
Function message (){
}
Function playMusic (){
}
Function photo (){
}
}
// Class instantiation
Class Person {
Var $ name;
Var $ age;
Var $ sex;
Function say (){
}
Function eat (){
}
Function run (){
}
}
// Instantiate
$ P1 = new Person;
$ P2 = new Person;
$ P3 = new Person;
// Access Object member
$ P1-> name = "zhangsan ";
Echo $ p1-> name;
?>

The http://www.bkjia.com/PHPjc/323522.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/323522.htmlTechArticle code is as follows :? Php/* class declaration * 1. what are you developing and are you sure you want to write? * 2. the members in the class must belong to this class * [modifier class keywords] class name {...

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.