Copy code The code is as follows:
class Cart{
public function Cart(){
echo "Calling Cart()
";
}
public function doSomething(){
echo "Calling doSomethimg()
";
}
}
class Named_Cart extends Cart{
function Named_Cart(){
echo "Calling Named_Cart()
";
}
function doSomething() {
echo "Calling Named_Cart::doSomething()
";
}
}
$myCart=new Cart();
$myCart->doSomething ();
$myNamed_Cart=new Named_Cart();
$myNamed_Cart->doSomething();
?>
When overriding the method, be sure to use The same conventions as the original method, including the parameters, must be consistent. Property overrides follow the same convention.
After overriding the method of the base class, you can still call the doSomething() method of the base class using the parent keyword instead of the doSomething() method in the current class.
http://www.bkjia.com/PHPjc/327489.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327489.htmlTechArticleCopy the code as follows: ?php class Cart{ public function Cart(){ echo "Calling Cart()br /"; } public function doSomething(){ echo "Calling doSomethimg()br /"; } } class...