Reply to comment

Name Based Dispatch

Here's a simple way to do name-based dispatch. $dispatchTable = array( 'First Thing' => 'functionName', 'Second Way' => array('ClassName', 'StaticMethod') ); ... ... $data = "Your data here, probably in an array."; call_user_func( $dispatchTable[ $name ], $data ); This is nice, because you can put the dispatch table at the top of your code, or in a separate file. I'm using it in a payment processing system, where different products may be dispatched to different code. You get a level of indirection here, where you can swap out different methods for each product (or use the same method). The only "trick" here is that, call_user_func() takes a pseudo-type known as a callback. Callbacks come in three forms:
string'fooFunc'this will call fooFunc()
arrayarray('Foo','func')this will call Foo::func()
arrayarray( $foo, 'func')this will call $foo->func()

Reply

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <b> <dd> <dl> <dt> <i> <li> <ol> <u> <ul> <p> <br> <div> <pre> <code> <img><h1><h2><h3><h4> <blockquote>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

.