Friday, October 22, 2004

PHP's call_user_func

Having been devoid of the pleasure of programming in PHP for a few weeks now I can't help but recall those joyful moments, those bliss filled hours spend typing away coding in PHP. One function I particularly fell inlove with is call_user_func().

Any information you ever want on this function you can find here:

Basically this function allows you to call a string in a variable as if it where a function within a class or reference of an object. You can also pas along other variables into the function and call these both by Value and by Reference. Al through the latter works a bit awkward with the '&' being "on the wrong side" of the call compared to the rest of PHP.

call_user_func() is more of less an eval() function on steroids and the potential to wreak havoc with it is beyond scary. In the wrong hands this functionality one could write the most un-maintainable code straight out of the pits of hell. The worst nightmare of any debugger!. But it's potential when used for good are just to yummy to ignore.

If your not familiar with the functionality, please remember that when you dynamically start calling functions you can really make the life of a debugger hell. So make sure you not just describe your API and code well, but also set your entire object structure up to be very transparent. For example: register all the functions you can call with a special function to register them (for example action1 triggers function1) and make sure the call to these functions also happens on a transparent and logical place within your code.

Also see: (also a dangerious function!)


Post a Comment

<< Home