> > The way that I have done this in the past is to use an associative
> > array to do the lookup of the name of the function to call.  It
> > ends up looking something like this:
> 
> If you name the option and the function the same thing, you could
> skip that step, no?
>

Yep, if you can use the same names that would be faster.  Several AJAX 
libraries do it that way.

But there are times when you can't or don't want to name them the same thing.  
I wanted to run a particular function whenever certain XML tags were 
encountered. (I had to be PHP 4 compatible, with a vanilla PHP installation so 
I couldn't use any of the newer fancy HTML libraries, just the SAX parser.)  

You also need to be careful about security when you are doing this.  You can 
imagine how bad something like this might be:

$funcname = $_GET['funcname'];
if (function_exists($funcname)) $funcname();

You've just opened the entire PHP API plus your entire app up to the world!!  
Using the associative array, you limit what functions can be called.  Calling 
methods on an object instead of functions in the global scope would also give 
you security and scalability.

--John


_______________________________________________

UPHPU mailing list
[email protected]
http://uphpu.org/mailman/listinfo/uphpu
IRC: #uphpu on irc.freenode.net

Reply via email to