Copy Code code as follows:
<?php
Class cart{
Public Function Cart () {
echo "is calling cart () <br/>";
}
Public Function dosomething () {
echo "is calling dosomethimg () <br/>";
}
}
Class Named_cart extends cart{
function Named_cart () {
echo "is calling Named_cart () <br/>";
}
function dosomething () {
echo "is calling Named_cart::d osomething () <br/>";
}
}
$myCart =new Cart ();
$myCart->dosomething ();
$myNamed _cart=new Named_cart ();
$myNamed _cart->dosomething ();
?>
When overriding a method, it is important to use the same conventions as the original method, including the parameters to be consistent. Property overrides also follow the same conventions.
After you override a method of a base class, you can still call the DoSomething () method of the base class, rather than the DoSomething () method in the current class, using the parent keyword.