Examples of definitions and inheritance usages of PHP classes

Source: Internet
Author: User

This article describes the definition and inheritance usage of PHP classes. Share to everyone for your reference. Specific as follows:

  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 "Name:" $this->name. "
    "." Age: ". $this->age;
  13. }
  14. function __tostring () {
  15. Return "Name:" $this->name. "
    "." Age: ". $this->age;
  16. }
  17. function __destruct () {
  18. echo "
    I am dead! ";
  19. }
  20. function __call ($key, $args) {
  21. echo "
    "," the method name you called does not exist: $key ","
    ";
  22. echo "The parameter you called is:", 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 ("little brother", "33");
  44. $pp->name = "Xiao Ming";
  45. $PP->age = "88";
  46. Echo $pp->name;
  47. Echo ';
  48. Echo $pp->age;
  49. Echo '

    ';
  50. $xx = new Xinxin ("small", "13");
  51. echo $xx->getname ();
  52. ?>
Copy Code

I hope this article is helpful to everyone's PHP programming.

Php
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.