PHP - Store functions to run later
Ideally what I want to have is a list of functions that can be run later. Depending on user input a function will then be chosen. The user will be then queried for parameters for that function. This will happen several times until the user inputs that they want all the functions to be run after each other.
I can't have a single form as there is not a fixed number of steps. The number of functions depends on the user. They will input the functions they want until they input that they want all functions to be run in the order they were inputed.
e.g. Input--Response A user will provide an input. -- run....... Depending on their input they will be asked for parameters.How far and how fast? -- 100 an开发者_如何转开发d 10......The function becomes run(100,10)
Another input -- shout.........Shout what? -- Hi........The function becomes shout(hi)
Next input --- jump ...... How high? -- 8......... Function would be jump(8)
After all that when the user gives the input "play", the following should be done in order: run(100,10), shout(hi), jump(8)
Thanks in advance :)
You can in the first step store the function name in a variable, and then use call_user_func($funcName, $arg1, $arg2, ..)
to call it with the arguments from the second step.
And if you try to call a method on a class and not global functions, you have to store it as array($instance, 'methodName')
, or array('className', 'methodName')
for static methods.
精彩评论