php - Abstract class calling a method from the wrong child class -
i have abstract class extended several other classes, each abstract method called child_save_changes()
.
one of methods in template class called on_save_changes()
, , whenever user clicks 'submit', method called page.
the on_save_changes()
method first sets class variables required validating/saving, calls child_save_changes()
, , handles redirection referring page.
the problem is, because i'm calling on_save_changes()
via callback page, doesn't know child class call abstract method child_save_changes()
from, , it's picking first 1 finds.
it seems inefficient repeat code in each child_save_changes()
method, i'm wondering if has come across similar scenario in past, , actions took fix issue? thanks.
it sounds me using static methods. otherwise problem describe cannot reasonably occur.
you wrote, "on_save_changes()
not know child class call abstract method child_save_changes()
from". ordinary (i.e., non-static) methods not called classes, called objects. , every object knows class belongs to, , there can never confusion method meant called.
static methods, on other hand, not designed work inheritance hierarchies that. recommend refactoring code , turn them non-static ones, if not want that, may able make work using late static binding.
Comments
Post a Comment