I want to have a dictionary of functions. Using this dictionary, I could have a handler that takes a function name and an array of arguments, and executes that function, returning a return value if it returns something. The handler throws an error if the name does not match the existing function.
It would be very simple to implement Javascript:
var actions = { doSomething: function(){ }, doAnotherThing: function() { } }; function runAction (name, args) { if(typeof actions[name] !== "function") throw "Unrecognized function."; return actions[name].apply(null, args); }
But since functions are not first class objects in PHP, I cannot figure out how to do this easily. Is there an easy way to do this in PHP?
source share