/*** inheritance, access control, static (static) keyword, rewrite, final keyword, data access supplement, interface, polymorphic, abstract class *
//*** 1. Static properties are used to hold the class's public data * 2. Static methods can only access static properties * 3. Static members can access * 4 without instantiating an object. The inside of a class can access its own static variable * 5 through the self or the static keyword. can be paren The T keyword accesses a static member of the parent class * 6. Static members can be accessed outside the definition of the class through the name of the class */Header"content-type:text/html; Charset=utf-8 ");//Remove Chinese garbled charactersDate_default_timezone_set ("PRC");//Set China time zone/** * Human class definition * / classHuman { Public$name;protected$height;//itself and sub-class accessible Public$weight; PublicStatic$staticValue="I am a static member of the Human class. "; Public functioneat($food){Echo$this->name."is eating".$food."
"; } }/** * Nbaplayer class definition * / classnbaplayerextendsHuman{//extends: Indicates inheritance, PHP extends can only follow the class name of a class (single inheritance principle)//Properties Public$team="PTS"; Public$playerNum="1221";Private$age= A;//static property definition PublicStatic$president="David";//static method definition PublicStatic functionchangepresident($newPresident){Static::$president=$newPresident;//self:: $president = $newPresident;//Use static members in the class definition, with Static or self:: static member Variable//Use the parent keyword to access the static members of the parental classEchoParent::$staticValue."
"; }//Constructors function__construct($name,$weight,$team,$playerNum ){Echo"Execute constructor ...
";$this->name=$name;//this is a pseudo-variable inside PHP that itself$this->weight=$weight;$this->team=$team;$this->playernum=$playerNum; }//destructor function__destruct(){Echo"Perform destructors ...
";; }//Definition method Public functionrun(){Echo"runing...\n"; } Public functionjump(){Echo"jumping...\n"; } Public functiondribble(){Echo"dribbling...\n"; } Public functionshoot(){Echo"shooting...\n"; } Public functiondunk(){Echo"dunking...\n"; } Public functionpass(){Echo"passing...\n"; } Public functiongetage(){Echo$this->name."This year".$this->age."years old."
"; } }//Instantiation of Class$pzy=NewNbaplayer ("Peng Zhongyao","182cm","75kg","PTS","1221");$pts=NewNbaplayer ("Peng","128cm","15kg","PTS","1221");Echo$pzy->name."\ n";Echo$pzy->eat ("Big Watermelon");//echo $pzy->age;$pzy->getage ();//Echo $pzy->name. " The President of the Alliance is ". $pzy->president;//x cannot access static members//Echo $pts->name. " The President of the Alliance is ". $pts->president;//class definition outside Access static member: Class Name:: Static member VariableEcho"former is". Nbaplayer::$president."
"; Nbaplayer::changepresident ("Pengdayao");Echo"Present is". Nbaplayer::$president."
";?>
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The above describes the object-oriented PHP (a), including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.