首页  >  文章  >  后端开发  >  php5类中三种数据类型的区别

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

WBOY
WBOY原创
2016-07-25 09:11:05953浏览
  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. ?>
复制代码


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn