Copy codeThe Code is as follows:
<? Php
Class Cart {
Public function Cart (){
Echo "calling Cart () <br/> ";
}
Public function doSomething (){
Echo "calling doSomethimg () <br/> ";
}
}
Class Named_Cart extends Cart {
Function Named_Cart (){
Echo "calling Named_Cart () <br/> ";
}
Function doSomething (){
Echo "calling Named_Cart: doSomething () <br/> ";
}
}
$ MyCart = new Cart ();
$ MyCart-> doSomething ();
$ MyNamed_Cart = new Named_Cart ();
$ MyNamed_Cart-> doSomething ();
?>
When overwriting a method, it is necessary to use the same conventions as the original method, including parameters. The same conventions are also observed for property overwrite.
After overwriting the methods of the base class, you can still use the parent keyword to call the doSomething () method of the base class, instead of the doSomething () method in the current class.