SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Thread: func_get_args?

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    336
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    func_get_args?

    Quick and stupid question. I want to search my template for a certain function and grab all the arguments. Can I use func_get_args for this?

    <p><?php abc( 'xyz' ); ?></p>
    ...
    <p><?php abc( '123' ); ?></p>

    - search and find function abc
    - get arguments
    - collect them in an array

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No. You will need to do some string parsing/tokenizing.

  3. #3
    ¬.¬ shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    If you are using PHP 5+ Reflection.
    But that only works on the signature of functions. Not how they are called.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  4. #4
    Floridiot joebert's Avatar
    Join Date
    Mar 2004
    Location
    Kenneth City, FL
    Posts
    823
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  5. #5
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    336
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks everyone, the token_get_all looks good, but I still have to get my head around getting the output needed, in addition, if I link up the functions like so:

    <?php abc('123'); abc('456');
    abc('91011');
    ?>
    I don;t get those functions outputted... I gotta look more into it.

    @logic - the reflection class is WAY over my head. You would have to show an example close to what I am looking for to get my head around it

  6. #6
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How robust do you need it?

    Do you need it to handle arguments which are functions themselves?
    Objects and methods?
    Operators in the argument list?
    PHP Code:
    abc(strlen($foo));
    abc($myObj->myMethod());
    abc($foo $bar $baz 2); 

  7. #7
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    336
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by crmalibu View Post
    How robust do you need it?

    Do you need it to handle arguments which are functions themselves?
    Objects and methods?
    Operators in the argument list?
    PHP Code:
    abc(strlen($foo));
    abc($myObj->myMethod());
    abc($foo $bar $baz 2); 

    Let me see if I can explain the problem better, perhaps that will help:

    The function (abc in this example) links a position in the template so extra content can be placed. This is usually found in the sidebars for ads and such, but this has been expanding further into the footer and the middle column. Each function call means another database call (that has been reduced from 2 calls to 1 – thanks to Rudy’s SQL book) and I would like to reduce that to one database call overall.

  8. #8
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Were still talking about parsing a string though, and the complexity of the needed parsing is unknown to anyone but you.

  9. #9
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    336
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by crmalibu View Post
    Were still talking about parsing a string though, and the complexity of the needed parsing is unknown to anyone but you.

    Sorry, yes the string will be similar to the original posting. Then it will be cleaned to check against entries in the database.

    <?php abc('xyz'); ?>
    <?php abc('html_block'); ?>
    Last edited by centered effect; May 6, 2009 at 21:24.


Bookmarks

Posting Permissions

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