...

View Full Version : Getting Function Arguments



Yaggles
06-18-2005, 07: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! :)

-Yaggles

Taylor_1978
06-18-2005, 08: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 :)

Yaggles
06-18-2005, 09: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, 04: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.

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

AaronW
06-19-2005, 12:15 AM
www.php.net/func_get_args

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.

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


<?php
$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";
}
?>

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

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

Thanks anyways.

marek_mar
06-19-2005, 11:19 PM
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).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum