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:
class MyOptions {
public function getType(){}
public function getStuff(){}
}
abstract class Cubique_Helper_Abstract {
abstract public function execute(MyOptions $options);
}
class Cubique_Helper_Doctype extends Cubique_Helper_Abstract{
public function execute(MyOptions $options) {
$type = $options->getType();
}
}
Or, you could make it depend on values in constructor and leave out the argument:
abstract class Cubique_Helper_Abstract {
abstract public function execute();
}
class Cubique_Helper_Doctype extends Cubique_Helper_Abstract{
public function __construct($type) {
// since __construct() is not in abstract, it can be different
// from every child class, which let's you handle dependencies
$this->type = $type;
}
public function execute() {
// you have $this->type here
}
}
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:
class Cubique_Helper_Doctype extends Cubique_Helper_Abstract {
public function execute() {
$args = func_get_args();
$type = $args[0];
$title = $args[1];
$content = $args[2];
// do something, for example
echo $type; // will always echo "" if you miss arguments, but you really want a fatal error
}
}
$d = new Cubique_Helper_Doctype();
$d->execute();
// this is a valid call in php, but it ruins your application.
// you **want** it to fail so that you know what's wrong (missing dependencies)
func_get_argsinstead of defining them in the signature. Or in the abstract class, you can define the method to accept one value, which is an (associative) array. In the child classes you just access the keys you need.