Home > Article > Backend Development > photoshop learning network php learning notes class declaration and object instantiation
Copy the code The code is as follows:
/* Class declaration
* 1. What are you going to develop? Determine what class to write
* 2. The members of the class must belong to this Class
* [Keywords that modify the class] class class name {
* Member attributes:
* Member methods:
* }
* 3. When declaring member attributes in a class, there must be a modifier in front of it. When you are not sure which one to use When using words, use var or public
* A file only saves one class, and the file name contains the class name. File: classname.class.php
* How to write the class name:
* Variable: aaaBbbCcc
* Function: aaaBbbCcc
* Constant: AAABBBCCC
* Class name: AaaBbbCcc
* 4. For member attributes in the class, if you create multiple objects and each object has different attribute values, 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 that creates an object. Creating an object means allocating a space in memory
*
* Only objects have storage space in memory
*
* The role of objects
*
* Allocation of objects in memory
*
* Use of objects
* Members in an object must be accessed through references to the object
* Object->Members
*
* Object->Member properties
* Object->Member methods
*
*
*
*/
//Declaration of class (phone class)
class Phone{
//Declaration of 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;
//Members of the access object
$p1->name="zhangsan";
echo $p1->name;
?>
The above introduces the declaration and object instantiation of the Photoshop Learning Network PHP Learning Notes class, including the content of the Photoshop Learning Network. I hope it will be helpful to friends who are interested in PHP tutorials.