Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Jan 2005
    Posts
    153
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Getting Function Arguments

    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

  • #2
    Regular Coder
    Join Date
    Jun 2003
    Location
    Australia
    Posts
    528
    Thanks
    8
    Thanked 8 Times in 8 Posts
    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

  • #3
    Regular Coder
    Join Date
    Jan 2005
    Posts
    153
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #5
    Regular Coder
    Join Date
    Jan 2005
    Posts
    153
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'll cehck around.

  • #6
    Senior Coder
    Join Date
    Feb 2003
    Location
    Ontario, Canada
    Posts
    1,223
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #7
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Something simple... I am bored...
    PHP Code:
    <?php
    $code 
    file_get_contents('../phpBB/includes/sessions.php');
    preg_match_all('/function (.+)[ ]?\((.*)\)/'$code$matchPREG_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";
    }
    ?>
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #8
    Senior Coder
    Join Date
    Feb 2003
    Location
    Ontario, Canada
    Posts
    1,223
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What if that .php file has some javascript in it, and that javascript has a function defined? Still bored? Hehe.

  • #9
    Regular Coder
    Join Date
    Jan 2005
    Posts
    153
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nevermind. My friend found out how to do it.

    Thanks anyways.

  • #10
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by AaronW
    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 (I see some problems with that too).
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •