Copy code The code is as follows:
/* Class declaration
* 1. You want to develop What is it, determine what class to write
* 2. The members in the class must belong to this class
* [Keywords that modify the class] class class name {
* member attributes:
* member Method:
* }
* 3. When declaring member attributes in a class, there must be a modifier in front of it. When you are not sure which word to use, use var or public
* A file only saves one class. The file name contains the class name, file: classname.class.php
* Class name writing:
* Variable: aaaBbbCcc
* Function: aaaBbbCcc
* Constant: AAABBBCCC
* Class Name: AaaBbbCcc
* 4. For member attributes in a class, if you create multiple objects and each object has a different attribute value, do not give the initial value directly. Give the value after the object is created
*
*
* Instantiate objects through classes
* 1. Use new to create a new object, plus the class name, which class object is created
* $Object reference=new class name ;
* 2. As long as there is a new keyword, an object is created. Creating an object is allocating a space in the memory
*
* Only objects have storage space in the memory
*
* The role of objects
*
* Allocation of objects in memory
*
* Usage of objects
* Members in the object must be accessed through references to the object
* Object->Members
*
* Object->Member Properties
* Object->Member Methods
*
*
*
*/
/ /Declaration of class (phone class)
class Phone{
//Declare attributes
var $pinPai;
var $color;
var $batteryCapacity;
var $screenSize;
//Member method
function call(){
}
function message(){
}
function playMusic(){
}
function photo(){
}
}
//Instantiation of class
class Person{
var $name;
var $age;
var $sex;
function say( ){
}
function eat(){
}
function run(){
}
}
//Instantiation
$p1=new Person;
$p2=new Person;
$p3=new Person;
//Access the members of the object
$p1->name="zhangsan";
echo $p1-> name;
?>
http://www.bkjia.com/PHPjc/323522.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323522.htmlTechArticleCopy the code as follows: ?php /* Class declaration* 1. What do you want to develop? Make sure to write What class* 2. Members in the class must belong to this class* [Keywords that modify the class] class class name {...