php5類中三種資料類型的區別

來源:互聯網
上載者:User
  1. /**

  2. * parent 只能調用父類中的公有或受保護的方法,不能調用父類中的屬性
  3. * self  可以調用父類中除私人類型的方法和屬性外的所有資料
  4. */
  5. class User{
  6. public $name;
  7. private $passwd;
  8. protected $email;
  9. public function __construct(){
  10. //print __CLASS__." ";
  11. $this->name= 'simple';
  12. $this->passwd='123456';
  13. $this->email = 'test123@163.com';
  14. }
  15. public function show(){
  16. print "good ";
  17. }
  18. public function inUserClassPublic() {
  19. print __CLASS__.'::'.__FUNCTION__." ";
  20. }
  21. protected function inUserClassProtected(){
  22. print __CLASS__.'::'.__FUNCTION__." ";
  23. }
  24. private function inUserClassPrivate(){
  25. print __CLASS__.'::'.__FUNCTION__." ";
  26. }
  27. }

  28. class simpleUser extends User {

  29. public function __construct(){
  30. //print __CLASS__." ";
  31. parent::__construct();
  32. }
  33. public function show(){
  34. print $this->name."//public ";
  35. print $this->passwd."//private ";
  36. print $this->email."//protected ";
  37. }
  38. public function inSimpleUserClassPublic() {
  39. print __CLASS__.'::'.__FUNCTION__." ";
  40. }
  41. protected function inSimpleUserClassProtected(){
  42. print __CLASS__.'::'.__FUNCTION__." ";
  43. }
  44. private function inSimpleUserClassPrivate() {
  45. print __CLASS__.'::'.__FUNCTION__." ";
  46. }
  47. }

  48. class adminUser extends simpleUser {

  49. protected $admin_user;
  50. public function __construct(){
  51. //print __CLASS__." ";
  52. parent::__construct();
  53. }
  54. public function inAdminUserClassPublic(){
  55. print __CLASS__.'::'.__FUNCTION__." ";
  56. }
  57. protected function inAdminUserClassProtected(){
  58. print __CLASS__.'::'.__FUNCTION__." ";
  59. }
  60. private function inAdminUserClassPrivate(){
  61. print __CLASS__.'::'.__FUNCTION__." ";
  62. }
  63. }

  64. class administrator extends adminUser {

  65. public function __construct(){
  66. parent::__construct();
  67. }
  68. }

  69. /**

  70. * 在類的執行個體中 只有公有屬性和方法才可以通過執行個體化來調用
  71. */
  72. $s = new administrator();
  73. print '-------------------';
  74. $s->show();
  75. ?>

複製代碼
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.