I have an abstract class and child’s:
abstract class Cubique_Helper_Abstract {
abstract public function execute();
}
class Cubique_Helper_Doctype extends Cubique_Helper_Abstract{
public function execute($type) {}
}
As you can see, method execute() is common. But number of arguments can be different in all classes. How can I keep this extending with different arguments of method?
It’s my current error:
Declaration of Cubique_Helper_Doctype::execute() must be compatible
with that of Cubique_Helper_Abstract::execute()
Thank you i advance.
You could remove
execute()from the abstract, but you probably do not want to do that.You could also give it an data object as argument, like this:
Or, you could make it depend on values in constructor and leave out the argument:
The last alternative is my favorite. This way, you really make sure you have the dependencies and when it’s time to
execute()you don’t have to give it any arguments.I would not use
func_get_args()since you lose track of dependencies. Example: