Copy CodeThe code is as follows:
/*
* 1. Access to members of the object (in an internal method of an object, to access the other methods and member properties in this pair of authoritative)
* 2. The method in the object has a $this keyword, which represents the object that called the method
*
* Construction Method
*
* 1. Is the "first" "Auto-call" method after object creation is complete
*
* 2. The definition of the constructor method, the method name is a fixed,
* in PHP4: The same method as the class name is the construction method
* in PHP5: The construction method is selected using the Magic Method __construct () All classes declare the constructor method using this name
* Advantages: The construction method does not change when changing the class name
* Magic method: In the class to write a magic method, the method corresponding to the function will add
* Method names are fixed (both are system-provided) and do not have their own defined
* Every Magic method is a method that is called automatically at different times in order to complete a function
* Different magic methods have different calling timing
* It's all a way to start with __
* __CONSTRUCT (); __destruct (); __set ();
*
* Function: Initialize the member property;
*
*
* Destructor method
*
* 1. Method that the last "automatic" call occurs before the object is released
* Use the garbage collector (Java PHP), and C + + manual release
*
* Role: Close some resources and do some cleanup work
*
* __DESTRUCT ();
*
*/
Class person{
var $name;
var $age;
var $sex;
The method of construction in PHP4
/*function person ()
{
Each object declared will be called
echo "1111111111111111";
}*/
The method of construction in PHP5
function __construct ($name, $age, $sex) {
$this->name= $name;
$this->age= $age;
$this->sex= $sex;
}
function say () {
$this access to members of the->name;//object using $this
echo "My name: {$this->name}, my age: {$this->age}
"
}
function Run () {
}
Function Eat () {
}
destructor method
function __destruct () {
}
}
$p 1=new person ("Zhangsan", 25, "male");
$p 2=new person;
$p 3=new person;
The above describes the Photoshop Learning Web site PHP Learning notes Object-oriented construction and destruction methods, including the Photoshop learning site content, I hope that the PHP tutorial interested in a friend to help.