<?php
Header ("Content-type:text/html;charset=utf-8");
/* $code = $_post["code"];
$name = $_post["Name"];*/
Classes and objects
A class is an abstraction of an object that is an instantiation of a class
Class Ren
{
Member variables
var $shengao;
var $tizhong;
var $name;
var $sex;
Member Properties---The PHP language is not
Member Methods
function Eat ()
{
echo "Eat with your Hand";
}
function Zoulu ()
{
echo "with feet, running, no";
}
}
To create an object, you must have a class
$wo =new Ren ();//Call class
$wo->name= "Zhang San";
echo $wo->name. " <br> ";
example, the area of the shaded portion of a circle with a different radius of two
Idea One: Layering
$R =10; $r =5 // large circle area $S =3.14* $R * $R // $s =3.14* $r * $r // shaded area $sss = $S - $s echo $sss ;
Idea two: Object-oriented
classcircle{var $r;//This radius belongs to the Circle classfunctionS () {$a=3.14*$this->r*$this->r;//$this->r represents the radius of this objectreturn $a;//you can return only values, and you cannot return other}}//Class Instantiation Object$dayuan=NewCircle ();//the object calls the class, and some of the classes can be called$dayuan->r=10;$DM=$dayuan-S ();$xiaoyuan=NewCircle ();$xiaoyuan->r=5;$XM=$xiaoyuan-S ();Echo($DM-$XM); //In the future, priority is given to object-oriented, that is, the subject involves two "circles" (objects), only a kind of "circle", create Class circle.
?>
PHP Object-oriented------------classes and objects