0

I have 3 classes

class Header
{
    public function _after_save ()
    {
    }
}

class Line extends Header
{

}

class Details extends Line
{

}

Line extends header and Details extend line. Header has a function which ‘ll be called many pages in my site & I have made it public. I don’t want when Line and Details class to call the function _after_save() to execute but it’s getting executed as are extended classes. I can’t make the function protected for obvious reasons. Any help how I can achieve this

sensorario
  • 20,262
  • 30
  • 97
  • 159
user2959149
  • 5
  • 2
  • 4

1 Answers1

2

You could create branched structure.

class AbstractHeader
{

}

class Header extends AbstractHeader
{
    public function _after_save ()
    {
    }
}

class Line extends AbstractHeader
{

}

class Details extends AbstractHeader
{

}
sectus
  • 15,605
  • 5
  • 55
  • 97
  • Thanks!!! Looks a good choice but I have to unnecessarily create an extra class.. what I am looking for is a feature which allows a function to be public & can be executed from out side the class But the child extended classesm wont inherit the function – user2959149 Nov 06 '13 at 08:01
  • @user2959149, you can override your function in child class and throw an excpetion there. – sectus Nov 06 '13 at 08:06
  • Thanks!!!Thats the last option just to define the function with out anything inside in all child extended classes but I was checking if there is any other elegant solution. Thanks again to you all for your valuable inputs!!! – user2959149 Nov 06 '13 at 08:29