Process oriented
Classes and objects anything can be called an object class instantiation of something that is a concrete piece of information
The abstraction of a class to all the same objects
Defining classes
Class Ren
{
var $name;//called member variable
var $age;
var $height;
var $sex; Do not assign a value to a member variable on one side
function __construct ($s)//constructor
{
$this->sex= $s;
}
function run ()//member functions (method)
{
echo "This man is running";
}
function Say ()
{
echo $this->name. " is talking ";
}
function __destruct ()//destructor object called before destruction
{
echo "The object to destroy";
}
function Setage ($a)//functions assigned to age
{
if ($a >10&& $a <50)
{
$this->age= $a;
}
}
function getage ()//value of age
{
return $this->age;
}
function __set ($name, $value)//Magic method for assigning a value to a private member inside a class * * *
{
$this $name = $value;
}
function __get ($name)//Magic method for the value of private members inside a class * * *
{
return $this $name;
}
}
Using classes
1 Instantiation of objects
$r =new Ren ("male");
2 assigning values to member variables (calling member variables)
$r->name= ' Zhang San '; Assigning a value to an object name
$r->setage (30);
$r->name= "John Doe";//Executes the statement automatically calls the __set method $r->__set ("name", "John Doe")
Var_dump ($R);
3 Member Methods
$r->say ();//Execute Member method
Access modifier public
1 If you want to add access modifiers you need to remove Var
2 access modifiers have three public protected protected PRIVATC private (can only be used in this class)
3 If no access modifier is public by default
$this reference It represents the object (which object call represents it).
constructor function
1 Special __construct
2 Perform the first execution of special objects at the time of creation
Action: Initialize an Object
Three main features of object-oriented
Packaging
Purpose: To make the class more secure and not allow direct access to the member variables within the class
Procedure: 1 Make the member variable private (PRIVATC)
2 To do a method to implement the value of a variable or to assign a value in the method to add a restriction condition
Using the Magic method in the class can also implement the operation of the private member
__set () Features: automatic execution, the variable name in the assignment statement as the first parameter, the variable name as the second parameter call __set () method
__get () Feature: automatically executes the variable name in the assignment statement as a parameter call __get () method
0426 Process-oriented