欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php5类中三种数据类型的区别

程序员文章站 2022-05-12 15:02:02
...
  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. ?>
复制代码