Simple implementation of PHP5 multi-Inheritance

Source: Internet
Author: User

InThe code for the multiple inheritance of PHP5 is as follows:

 
 
  1. <? 
  2. // PHP5 interface --- similar to JAVA ~ Dizzy
  3. Interface IFOne {
  4. Function getName ();
  5. }
  6. Interface IFTwo {
  7. Function getID ();
  8. }
  9. // PHP abstract class
  10. Abstract class AbsClsOne {
  11. Var $ name;
  12. Function setName ($ name ){
  13. $ This->Name= $ Name;
  14. }
  15. }
  16. Abstract class AbsClsTwo {
  17. Var $ id;
  18. Function setID ($ id ){
  19. $ This->Id= $ Id;
  20. }
  21. }
  22. // Multiple implementations of single inheritance
  23. Class ExtendsMoreCls extends AbsClsOne implements IFOne, IFTwo {
  24. Var $ id;
  25. Private static $PriVar="Private";
  26. Function _ construct () {// PHP5 Constructor
  27. Self: $PriVar="Set private";
  28. $ This->Id=0;
  29. }
  30. Function _ destruct () {// destructor
  31. Echo "ExtendsMoreCls destruct ";
  32. }
  33. Function getName (){
  34. Return $ this->Name;
  35. }
  36. Function getID (){
  37. Return $ this->Id;
  38. }
  39. Public static function clsStaticFunc (){
  40. Echo "static function ";
  41. }
  42. }
  43.  
  44. $Emc=NewExtendsMoreCls ();
  45. $ Emc->SetName ("kj021320 ");
  46. Echo $ emc->GetName ();
  47. Echo"<Br>";
  48. Echo $ emc->GetID ();
  49. Echo"<Br>";
  50. ExtendsMoreCls: clsStaticFunc (); // call the static method
  51. Echo"<Br>";
  52. ?> 

The output structure is

Kj021320
0
Static function
ExtendsMoreCls destruct

It is hoped that the implementation code of PHP5 multi-inheritance can be helpful to friends in need.


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.