The examples in this article describe the definition and inheritance usage of PHP classes. Share it with everyone for your reference. The details are as follows:
-
- /*
- * class
- */
- class people {
- public $name;
- public $age;
- function __construct($namec,$agec) {
- $this->name = $namec;
- $this->age = $agec;
- }
- protected function getmessage() {
- return "Name:".$this->name."
"."Age: ".$this->age;
- }
- function __tostring() {
- return "Name: ".$this->name."
"."Age: ".$this-> age;
- }
- function __destruct() {
- echo "
I am dead!";
- }
- function __call($key,$args) {
- echo "
"," The method name you called does not exist: $key"," ";
- echo "The parameters you called are:",var_dump($args);
- }
- final function getf() {
- echo " I am getf";
- }
- }
- class xinxin extends people {
- function getname() {
- echo $this->getmessage();
- echo '
';
- echo parent::getmessage( );
- echo '
';
- return "I am xinxin";
- }
- function getmessage() {
- return "I am zilei getmessage
";
- }
- function getff( ) {
- echo "I am new getf";
- }
- }
- $pp = new people("小哥","33");
- //$pp->name = "Xiao Ming";
- //$pp ->age = "88";
- echo $pp->name;
- echo ' ';
- echo $pp->age;
- echo '
';
- $xx = new xinxin("小小","13");
- echo $xx->getname();
- ?>
-
-
Copy code
I hope this article will be helpful to everyone’s PHP programming design.
|