View Full Version : Getting Function Arguments

06-18-2005, 08:51 AM
I need to get a list of arguments from all functions in a specific class. Can anyone show me how to do so? This is quite urgent! :)


06-18-2005, 09:10 AM
Well... someone else might be able to answer, but from my perspective - you need to be more specific. Show us some code! Where is the function at, what page are you calling them to.. etc :)

06-18-2005, 10:43 AM
I don't have any function yet...

Here's what I need:
1) The two thigns in my first post
2) My friend knows what he is going to do from there.

All I need to know is how to get the arguments from a function; not the values of the argument, but the actual arguments. He doesn't need them in an array; he'll do that himself.

Kid Charming
06-18-2005, 05:22 PM
You mean the parameters? There's not a native function for that, but you could set up a script that'll read your file and pull out all the function declarations and make a list from that.

There may already be some scripts floating around that'll do something like that (PHPDoc, for example). Do a bit of Googling; you may get lucky.

06-18-2005, 11:49 PM
I'll cehck around.

06-19-2005, 01:15 AM

Only works inside the function though. As for getting the actual function key from outside the function's scope, I'm pretty sure that's as impossible as it is useless :P Just save it as a .txt file and use a regular expression to parse out the argument names.

06-19-2005, 01:32 AM
Something simple... I am bored...

$code = file_get_contents('../phpBB/includes/sessions.php');
preg_match_all('/function (.+)[ ]?\((.*)\)/', $code, $match, PREG_PATTERN_ORDER);
for ($i = 0, $n = count($match[0]); $i < $n; $i++) {
print 'Function: ' . $match[1][$i] . ' takes the arguments: ' . $match[2][$i] . "<br />\n";

06-19-2005, 12:40 PM
What if that .php file has some javascript in it, and that javascript has a function defined? ;) Still bored? Hehe.

06-19-2005, 02:03 PM
Nevermind. My friend found out how to do it.

Thanks anyways.

06-20-2005, 12:19 AM
What if that .php file has some javascript in it, and that javascript has a function defined? ;) Still bored? Hehe.
Hmm... good question. ;) That would require checking if we're in JS or if were in PHP... but you can be in both if you print a JS function... or you could just strip the JS out :p (I see some problems with that too).