Home > Backend Development > PHP Tutorial > The difference between the three data types in php5 classes

The difference between the three data types in php5 classes

WBOY
Release: 2016-07-25 09:11:05
Original
981 people have browsed it
  1. /**

  2. * parent  Only public or protected methods in the parent class can be called, and attributes in the parent class cannot be called
  3. * self  All data in the parent class except private type methods and attributes can be called
  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. * In an instance of a class, only public properties and methods can be called through instantiation
  71. */
  72. $s = new administrator();
  73. print '-------------------';
  74. $s->show();
  75. ?>

复制代码


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template