SitePoint Sponsor |
|
User Tag List
Results 1 to 9 of 9
Thread: func_get_args?
-
May 5, 2009, 11:11 #1
- 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
-
May 5, 2009, 11:32 #2
- 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.
-
May 5, 2009, 16:18 #3
If you are using PHP 5+ Reflection.
But that only works on the signature of functions. Not how they are called.
-
May 6, 2009, 02:32 #4
- Join Date
- Mar 2004
- Location
- Kenneth City, FL
- Posts
- 823
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Does this help ?
http://www.php.net/token_get_all
-
May 6, 2009, 07:28 #5
- 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
-
May 6, 2009, 07:49 #6
- 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 + 1 : $baz / 2);
-
May 6, 2009, 08:49 #7
- Join Date
- Dec 2005
- Posts
- 336
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
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.
-
May 6, 2009, 08:56 #8
- 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.
-
May 6, 2009, 09:07 #9
- Join Date
- Dec 2005
- Posts
- 336
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Bookmarks