Mother Function of A local variable
Moderator: General Moderators
http://de3.php.net/tokenizer may help you build a parser.
That would return iamnotwhatyouareafter in the following snippet, while you seek the "mother" of $seekme:neel_basu wrote:Ya I've Got The idea In My Mind.We Can Do it
We Can Create A Funcion That Will Treat $_SERVER["PHP_SELF"] as a Text file
and search for the Variable name in it.
And Store the line number (s) of its occurences in an Array ( Suppose $arr_var ) descending
and Then search for the string "function" And store the line number (s) of its occurences in an another array ( Suppose $arr_func ) descending
As Occurences of one variable in a Function may be 1 or many so
in a for loop it Would first hold the $arr_var[$i] and then start another loop
for($j=0;$j<=$arr_var[$i];$j++) And Find the nearest line number ( nearest with $arr_var[$i] ).
And In that line The mother Function Stayes
So Now we will find the String after "function " and before "(" and trim() it To get The Function name
and that function would take the variable name (as string) as argument
and make output of the name of the function(s) (as string) if more than 1 function names are found it would use a separater as "-" or "," and return the string
( We Can explode it latter fo further use )
Code: Select all
function iamnotwhatyouareafter() {
...
}
$seekme = true;Before You mention that
Code: Select all
$iamaglobalvariable = true;
function firstlevelfunction() {
function secondlevelfunction() {
...
}
$seekme = true;
}Anyway, when You refer to $_SERVER["PHP_SELF"] keep in mind, that it points to the actual php script, so You don't really want to use it in your "parser", do you?
Cheers.
- neel_basu
- Forum Contributor
- Posts: 454
- Joined: Wed Dec 06, 2006 9:33 am
- Location: Picnic Garden, Kolkata, India
Thanks.szaky wrote:That would return iamnotwhatyouareafter in the following snippet, while you seek the "mother" of $seekme:
Ok, in that case the var $seekme is a global variable, not a local.Code: Select all
function iamnotwhatyouareafter() { ... } $seekme = true;
Before You mention that, here's another:
=========================================================Your "parser" would return the secondlevelfunction whilst should return firstlevelfunction.Code: Select all
$iamaglobalvariable = true; function firstlevelfunction() { function secondlevelfunction() { ... } $seekme = true; }
Anyway, when You refer to $_SERVER["PHP_SELF"] keep in mind, that it points to the actual php script, so You don't really want to use it in your "parser", do you?
Cheers.
I think You have very good eyes.
I am now Thinking about it
By the way
It Can't Search for the ending "}" after the variable Cause There May be Some if or else or switch in the function
But I am still Thinking About Its Solution
edit()
{
Ya I think we can Do it in this way First It We Cheak If Its in $GLOBALS array or not
Then Procced if Its A member then it would return -1 else it would proccedd
}