Php class and object. Php class and object-oriented programming are the mainstream today. for R & D personnel, there may be more or less understanding of object-oriented, however, some of the less commonly used php classes and objects may not be particularly clear.
Object-oriented is the mainstream of today's programming. for R & D personnel, there may be more or less understanding of object-oriented, but some of the less commonly used ones may not be particularly clear. It is sometimes useful. The following describes some knowledge.
I. knowledge about final Keywords:
1. the final keyword can be inherited by the quilt class as a method. As shown below:
class A{ final function operation(){ echo 'a'; }}class B extends A{}$a=new B();$a->operation();
Result:
2. the final keyword as a class cannot be inherited, as shown below:
operation();
The following error occurs:
(! ) Fatal error: Class B may not inherit from final class (A) in D: \ wamp \ www \ examble \ index19.php on line9
3. the final keyword as a method cannot be overwritten by the quilt class, that is, the subclass cannot have the same method, as shown below:
class A{ final function operation(){ echo 'a'; }} class B extends A{ function operation(){ echo 'a'; }}$a=new B();$a->operation();
The following error occurs:
(! ) Fatal error: Cannot override final method A: operation () in D: \ wamp \ www \ examble \ index19.php on line12 |
2. php multi-inheritance implementation. the following example will cause a fatal error in php.
class A{ public function operation(){ echo 'a'; }}class C{ public function oper(){ echo 'c'; }} class B extends A{ public function operation(){ echo 'a'; }} class B extends C{ public function operati(){ echo 'd'; }}$a=new B();$a->operation();
(! ) Fatal error: Cannot redeclare class B in D: \ wamp \ www \ examble \ index19.php on line24 |
Multiple inheritance types in this form are not allowed.
If you have to implement multiple types of inheritance, you can only implement it through interfaces.
interface Displayable{ public function display(); } interface B{ public function show(); } class A implements Displayable,B{ public function display(){ echo 'a'; } public function show(){ echo 'b'; } } $ab=new A(); $ab->display(); $ab->show();
Note that the interface methods are all public, the interface methods only have methods, there is no method body, the subclass overrides the interface method, the interface methods must be overwritten in the subclass.
Http://www.bkjia.com/PHPjc/941436.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/941436.htmlTechArticlephp class and object-oriented, is the mainstream of today's programming, for R & D personnel, may have some understanding of object-oriented, more or less, but some not commonly used may not be particularly clear...