Reputation: 2421
I am working on a Gearman client-worker script. Can we declare the Gearman callbacks methods as protected or private? i.e.
$this->gearmanClient->setCompleteCallback(array($this, 'JobComplete'));
$this->gearmanClient->setFailCallback(array($this, 'JobFailCallBack'));
What is best access operator to be used with the 'JobComplete' methods etc?
Upvotes: 0
Views: 494
Reputation: 1897
Of course we can. Just wrap it around closure:
$this->gearmanClient->setCompleteCallback(function () {
$this->JobComplete();
});
Upvotes: 1
Reputation: 2493
In PHP, private / protected callbacks are only accesible if called from the right context (e.g. within the class that has access to those callbacks) - see here for discussion.
In your case, the GearmanClient class will not have access to the callback (unless you do some really weird abstractions around it). So the answer is no, you cannot.
As for the access operator question (if I understand correctly - whether to use object callbacks or class callbacks), I guess the answer is - it depends. If your callback will provide data about a particular object, then it makes sense for that object to receive the callback. If it's a generic message that your app will just store in DB, a static class interface can do that, too.
Upvotes: 3