<?php
Package __set () __get () __isset () __unset ()
The __get () function ==> represents a call to a private property and does not call the method if it accesses the generic member property
/*class person{
Private $age;
function __get ($var) {
echo "hahaha". $var;//var represents the variable being called
return $this $var;
}
}
$p =new person ();
Echo $p->age;
Class person{
Private $name;
Private $age;
function __get ($var) {
if ($var = = "Name")
return $this->name;
if ($var = = "Age")
return $this->age;
}
function __set ($var, $value) {
if ($var = = "Name")
return $this->name= $value;
if ($var = = "Age")
return $this->age= $value;
}
}
Class Student extends person{
function Say ($AVR) {
echo $this->name. " Say ". $avr;
}
}
$s =new Student ();
$s->__set ("name", "Zhang San");
$s->say ("haha haha");
The static property ==> This class name call can use self, but externally it has to be called with the class name
Class person{
var $name;
Static $country = "China";
function Say () {
echo "I am." Self:: $country. " Person ";//person:: $country
}
}
$p =new person ();
Person:: $country = "Alien";
$p->say ();
The static method can be called by either of the following methods
Class person{
var $name;
Static $country = "China";
function Say () {
echo "I am." Self:: $country. " People ";
}
}
Person::say ();//Recommended Use
$p =new person ();
$p->say ();
CONST constant Modifier
Class person{
var $name = "I";
Const country= "China";//constants Cannot change values
function Say () {
echo "I am". Self::country. " People ";
}
}
Person::say ();
The value of a string must be returned when the __tostring () function ==> is defined
Class person{
var $name = "I";
function __tostring () {
Return "This is an object type and cannot be output directly";
}
}
$p =new person ();
Echo $p;
The __clone () function ==> clones a new object with the same contents as the two objects, but not the same address in the heap
Class person{
var $name = "I";
function __clone () {
$this->name= "is clone out of copy";
}
}
$p =new person ();
$e =new person ();
$e =clone $p;
Echo $p->name;
Echo $e->name;
__call () function ==> can avoid program crash, only output a hint content
Class person{
var $name = "I";
function __call ($funname, $args) {//The first parameter is the method name of the call. The second argument is the one passed when the method is called.
echo $funname. " method does not exist <br> ";
Print_r ($args);
}
}
$p =new person ();
$p->fun (a);
echo "<br> program not Crashing";
Abstract methods, a class has abstract methods are abstract classes, abstract classes can not be instantiated, can only be implemented by inheritance
Abstract class demo{
Abstract function fun1 ();
function fun2 () {
echo "hahaha";
}
}
Class Test extends demo{
function Fun1 () {
echo "Overlay abstract method";
}
}
Test::fun1 ();
$t =new Test ();
$t->fun1 ();
An interface is a special kind of abstract class.
All member properties must be constants, all methods are abstract, and all members must be public
Class demo{
}
Interface lone{
Const b= "HHHH";
function Fun ();
}
Class One extends Demo implements lone{
function Fun () {
echo "haha haha";
}
}
One::fun (); */
PHP Object-oriented