I'm writing a class that accepts a SQL query and outputs an HTML table of the results. It's designed so you can do some pretty extensive formatting of individual columns.
I'd like to give the user the ability to process particular column data with a custom function handler - for example, they might want to process a field that contains a dollar amount by running it through a function that prepends a dollar sign and inserts commas between grouped thousands. Something like this:
$foo = new MyClass();
$foo->addCustomHandler( 'column_name', [specify handler function here] );
Currently, the class user passes in the name of the handler function as a string, and the class invokes it with eval(). This works, but using eval() makes my skin crawl - it's just not an elegant way to do things.
In JavaScript, functions are objects, so you can pass them around and reference them like any other variable, but that's not the case in PHP.
Can anyone think of a way to do this that doesn't involve eval()? I'd prefer to avoid kludges.