[SOLVED] Chain of command where valid return may be empty

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

[SOLVED] Chain of command where valid return may be empty

Post by Chris Corbyn »

I think this would be classified as chain of command, although it's kind of like the strategy too.

Code: Select all

interface Command {
  public function execute($data);
}
 
...
public function whatever($data) {
  foreach ($this->_commands as $command) {
    if ($ret = $command->execute($data)) {
      return $ret;
    }
  }
}
That works well when you expect a return value, but what if you don't expect a return value and the chain still has to be broken?

EDIT | Sorry, having a blonde moment; I should be using a filter chain.
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Re: [SOLVED] Chain of command where valid return may be empty

Post by matthijs »

Isn't easy isn't it, after a few nights partying? :)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: [SOLVED] Chain of command where valid return may be empty

Post by Chris Corbyn »

matthijs wrote:Isn't easy isn't it, after a few nights partying? :)
That's how I roll ;)
Post Reply