Object-oriented:
<?PHP//class//object//class is an abstraction of an object; An object is an instantiation of a classclassren{//member Variables var $top; var $zhong; var $sex; var $name; //member properties are not in PHP;//Member Methods functionEat () {Echo"Eat with your hands."; } functionRun () {Echo"Run fast."; }}//Class Instantiation Object$r=NewRen ();$r->name = "Zhang Da";Echo $r->name
For example, to the circle area
For simple calculations, it may be a bit more complex for object-oriented, but it is more convenient for more complex and frequently changed data code.
//Object-oriented//storage radius variable classyuan{//defines the radius of a circle var $banjing; //method of Calculating Circle area functionMianji () {return3.14*$this->banjing*$this-banjing; } }//Find Area$r 1=NewYuan;$r 1->banjing=10;$DMJ=$r 1-Mianji ();$r 2=NewYuan;$r 2->banjing=5;$XMJ=$r 2-Mianji ();Echo $DMJ-$XMJ;?>
Object Oriented PHP learning notes (top)