简体   繁体   中英

PHP - using public function in one class but not in extended classes

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

You could create branched structure.

class AbstractHeader
{

}

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

class Line extends AbstractHeader
{

}

class Details extends AbstractHeader
{

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM