I’m currently doing it this way, but seems to not be the proper way:
class Name
{
protected $jobs2do;
public function __construct($string) {
$this->jobs2do[] = $this->do;
}
public function do() {
...
}
}
Because directly assign a function will cause warning, should do something like:
function func()
{
...
}
$func_array[] = 'func';
say, put it into a string, but I don’t know how to do it when it’s a member function.
Is the following version OK?:
class Name
{
public $jobs2do;
public function __construct($string) {
$this->jobs2do[] = array($this,'do');
}
public function do() {
...
}
}
when call it, just:
$instance = new Name();
foreach ($instance->jobs2do as $job)
{
call_user_func($job);
}
Write a class for Job and use factory pattern to create them. Then Write a class JobManager wihich should maintain a list ob Job instances.