To explore the method of rewriting of overburden in detail

  • 2020-06-07 04:07:39
  • OfStack

 class Cart{
  public function Cart(){
   echo " Is called Cart()<br />";
  public function doSomething(){
   echo " Is called doSomethimg()<br />";
 class Named_Cart extends Cart{
  function Named_Cart(){
   echo " Is called Named_Cart()<br />";
  function doSomething(){
   echo " Is called Named_Cart::doSomething()<br />";
$myCart=new Cart();
$myNamed_Cart=new Named_Cart();

When overwriting a method, it is important to use the same convention as the original method, including 1 argument. Property overrides follow the same convention.
After overriding the methods of the base class, the doSomething() method of the base class can still be called using the parent keyword, rather than the doSomething() method in the current class.

Related articles: