2

I have following class structure

class A 
{
  function aa(){
   //do something in aa
   $this->ab();
  }

  function ab(){
   //do something in ab
  }
}

Class B extends A
  function ab(){
   //do something else in ab
  }
}

$b = new B();
$b->aa();

When I call aa() from the object of class B, how can I override the method ab, to make sure its called from class B?

1
  • its working! preconditions were not being met! Commented Dec 15, 2016 at 3:10

1 Answer 1

2

class B -> ab() called;

<?php
    class A 
    {
      function aa(){
       //do something in aa
       $this->ab();
      }

      function ab(){
       //do something in ab
       echo "class A\n";
      }
    }

    Class B extends A { 
      function ab(){
       //do something else in ab
       echo "class B\n";
      }
    }

    $b = new B();
    $b->aa();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.