johanna Posted June 1, 2007 Share Posted June 1, 2007 Hi, I am looking to get the default arguments in a user function. I know that you can use get_defined_functions() to get all the functions, and I know that you can also get the arguments within the function, with func_get_args(). But is it possible to get the argument variable names (or keys) before calling the function? Here is what I need. Say I have a function with args: function foo($something, $another=''){ return $something.$another; } Is there a way to get the variable/arg names, "$something" and "$another" from the functions? For you c programmers, I am looking for something like inspect.getargspec() but that is for PHP Quote Link to comment Share on other sites More sharing options...
per1os Posted June 1, 2007 Share Posted June 1, 2007 I do not think it is possible, but what would be the point of the function to just return the arguments names? I mean if that function is what you want this would work... function foo($something, $another=''){ return '$something' . '$another'; } But I think you want it for existing functions, I really do not think it is possible. If it is you will find it somewhere in here: http://us.php.net/manual/en/ref.funchand.php Quote Link to comment Share on other sites More sharing options...
johanna Posted June 2, 2007 Author Share Posted June 2, 2007 Thanks for the reply. I am pretty familiar with all the those functions ... and it's not really what I am looking for, but rather like inspect.getargspec() in C. We have a program that was developed by a programmer who ioncubed portions of it before abandoning the project, without our knowledge or consent. We are perusing court action, but it's a long process. In the meantime we need to build some additional functionality quite urgently. Using get_defined_functions() we are able to get the function names, we can do the same for classes. But we can't figure out the arguments. If anyone knows anyway to do this, I would greatly appreciate any pointers. Quote Link to comment Share on other sites More sharing options...
taith Posted June 2, 2007 Share Posted June 2, 2007 sure its possible... http://ca.php.net/manual/en/function.func-get-args.php Quote Link to comment Share on other sites More sharing options...
per1os Posted June 2, 2007 Share Posted June 2, 2007 sure its possible... http://ca.php.net/manual/en/function.func-get-args.php No, he doesn't want to just get random argument values. He wants to get the argument names of each function. So in this function function foo($passed, $in) { return "I was passed in"; } It would return him $passed and $in. Now I do not think there is any current functionality in php. But if you know C you may be able to create your own extension dll for just this, I would check out the core hacking section. I think you are at a loss to create your own functionality. Quote Link to comment Share on other sites More sharing options...
johanna Posted June 5, 2007 Author Share Posted June 5, 2007 Yes, frost110, you understood correctly. I guess I'll have to attempt it in C. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.