PHP class definition and inheritance usage examples, PHP inheritance usage examples_PHP tutorial

WBOY
Release: 2016-07-13 09:47:07
Original
776 people have browsed it

Definition and inheritance usage examples of php classes, php inheritance usage examples

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:

<&#63;php
/*
 * class
 */
 class people {
  public $name;
  public $age;
  function __construct($namec,$agec) {
    $this->name = $namec;
    $this->age = $agec;
  }
  protected function getmessage() {
    return "姓名:".$this->name."<br/>"."年龄:".$this->age;
  }
  function __tostring() {
    return "姓名:".$this->name."<br/>"."年龄:".$this->age;
  }
  function __destruct() {
    echo "<br/> I am dead!";
  }
  function __call($key,$args) {
    echo "<br/>","你调用的方法名不存在:$key","<br/>";
    echo "你调用的参数是:",var_dump($args);
  }
  final function getf() {
    echo "I am getf";
  }
 }
 class xinxin extends people {
  function getname() {
    echo $this->getmessage();
    echo '<br/>';
    echo parent::getmessage();
    echo '<br/>';
    return "I am xinxin";
  }
  function getmessage() {
    return "I am zilei getmessage <br/>";
  }
  function getff() {
    echo "I am new getf";
  }
 }
$pp = new people("小弟","33");
//$pp->name = "小明";
//$pp->age = "88";
echo $pp->name;
echo '   ';
echo $pp->age;
echo '<br/><br/>';
$xx = new xinxin("小小","13");
echo $xx->getname();
&#63;>

Copy after login

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1028299.htmlTechArticleDefinition and inheritance usage examples of php classes, php inheritance usage examples This article tells the definition and inheritance usage examples of php classes . Share it with everyone for your reference. The details are as follows: php/* * class */...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!