php類的定義與繼承用法執行個體

來源:互聯網
上載者:User

本文執行個體講述了php類的定義與繼承用法。分享給大家供大家參考。具體如下:

  1. /*
  2. * class
  3. */
  4. class people {
  5. public $name;
  6. public $age;
  7. function __construct($namec,$agec) {
  8. $this->name = $namec;
  9. $this->age = $agec;
  10. }
  11. protected function getmessage() {
  12. return "姓名:".$this->name."
    "."年齡:".$this->age;
  13. }
  14. function __tostring() {
  15. return "姓名:".$this->name."
    "."年齡:".$this->age;
  16. }
  17. function __destruct() {
  18. echo "
    I am dead!";
  19. }
  20. function __call($key,$args) {
  21. echo "
    ","你調用的方法名不存在:$key","
    ";
  22. echo "你調用的參數是:",var_dump($args);
  23. }
  24. final function getf() {
  25. echo "I am getf";
  26. }
  27. }
  28. class xinxin extends people {
  29. function getname() {
  30. echo $this->getmessage();
  31. echo '
    ';
  32. echo parent::getmessage();
  33. echo '
    ';
  34. return "I am xinxin";
  35. }
  36. function getmessage() {
  37. return "I am zilei getmessage
    ";
  38. }
  39. function getff() {
  40. echo "I am new getf";
  41. }
  42. }
  43. $pp = new people("小弟","33");
  44. //$pp->name = "小明";
  45. //$pp->age = "88";
  46. echo $pp->name;
  47. echo ' ';
  48. echo $pp->age;
  49. echo '

    ';
  50. $xx = new xinxin("小小","13");
  51. echo $xx->getname();
  52. ?>
複製代碼

希望本文所述對大家的php程式設計有所協助。

php
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.