Share the differences among the three data types in php5: php5 data type. Share the differences among the three data types in the php5 class. the php5 data type is public: the public type can be passed through self :: you can use parent to share the differences between the three data types in the php5 class and the php5 data type.
Public: public type
In the subclass, you can use self: var to call public methods or attributes. you can use parent: method to call methods in the parent class.
You can use $ obj-> var to call public methods or attributes in an instance.
Protected: protected type
In the subclass, you can use self: var to call the protected method or attribute. you can use parent: method to call the method in the parent class.
You cannot use $ obj-> var to call a protected method or attribute in an instance.
Private: private type
Attributes or methods of this type can only be used in this class. Private attributes and methods cannot be called in instances of this class, subclass, and subclass.
2. differences between self and parent
A) These two pairs are often used in subclasses. Their main difference is that self can call public or protected attributes in the parent class, but parent cannot call
B). self: it indicates that the static member (method and attribute) of the current class is different from $ this. $ this indicates the current object.
Code:
<? Php/*** parent can only call public or protected methods in the parent class, attribute * self in the parent class cannot be called. all data except private methods and attributes in the parent class can be called */class User {public $ name; private $ passwd; protected $ email; public function _ construct () {// print _ CLASS __. ""; $ this-> name = 'simple'; $ this-> passwd = '000000'; $ this-> email = 'bjbs _ 270@163.com ';} public function show () {print "good";} public function inUserClassPublic () {print _ CLASS __. '::'. _ FUNCTION __. "";} pro Tected function inUserClassProtected () {print _ CLASS __. '::'. _ FUNCTION __. "";} private function inUserClassPrivate () {print _ CLASS __. '::'. _ FUNCTION __. "" ;}} class simpleUser extends User {public function _ construct () {// print _ CLASS __. ""; parent ::__ construct ();} public function show () {print $ this-> name. "// public"; print $ this-> passwd. "// private"; print $ this-> email. "// protected";} pu Blic function inSimpleUserClassPublic () {print _ CLASS __. '::'. _ FUNCTION __. "";} protected function inSimpleUserClassProtected () {print _ CLASS __. '::'. _ FUNCTION __. "";} private function inSimpleUserClassPrivate () {print _ CLASS __. '::'. _ FUNCTION __. "" ;}} class adminUser extends simpleUser {protected $ admin_user; public function _ construct () {// print _ CLASS __. ""; parent ::__ construct ();} p Ublic function inAdminUserClassPublic () {print _ CLASS __. '::'. _ FUNCTION __. "";} protected function inAdminUserClassProtected () {print _ CLASS __. '::'. _ FUNCTION __. "";} private function inAdminUserClassPrivate () {print _ CLASS __. '::'. _ FUNCTION __. "" ;}} class administrator extends adminUser {public function _ construct () {parent ::__ construct ();}} /*** only public attributes and methods can be called through instantiation in class instances */$ s = new adm Inistrator (); print '-----------------'; $ s-> show ();?>
Extends public: The public type can be called using self: var in the subclass to call public methods or attributes through parent...