Object oriented
1. Class
Abstracted by a multitude of objects.
2. Objects
All objects together
instantiated by the class.
Find the area of the shadow between two circles
$SR 1=10;
$SR 2=5;
$MJ =3.14* $sr 1* $sr 1-3.14* $sr $SR 2;
Echo $MJ;
Process-oriented approach
1. Abstract a circle into a class;
Class Yuan
{
var $banjing;//A member variable of a circle class
Area, member method
function Mianji ()
{
return 3.14* $this->banjing* $this->banjing;
}
}
Instantiating an Object
$yuan = new Yuan ();//new an object from an abstract model that is created as an instance
$yuan->banjing=10;//using Object tuning members
echo $yuan->mianji ();//Call method
Var_dump ($yuan);
$this keyword represents the object inside a class
Making a great circle
$maxyuan =new yuan ();
$maxyuan->banjing=10;
Making small Circles
$minyuan =new yuan ();
$minyuan->banjing=5;
echo= $maxyuan->mianji ()-$minyuan->banjing ();
PHP Object-oriented