Mother Function of A local variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

I sifted through the thread in search for a conceivable problem for which this function would solve, but didn't find any. I think you may be a little confused about variable scope.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

http://de3.php.net/tokenizer may help you build a parser.
User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post by neel_basu »

Thanks
szaky
Forum Newbie
Posts: 1
Joined: Fri Jan 05, 2007 10:42 am

Post by szaky »

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 )
That would return iamnotwhatyouareafter in the following snippet, while you seek the "mother" of $seekme:

Code: Select all

function iamnotwhatyouareafter() {
  ...
}
$seekme = true;
Ok, in that case the var $seekme is a global variable, not a local.
Before You mention that :) , here's another:

Code: Select all

$iamaglobalvariable = true;
function firstlevelfunction() {
  function secondlevelfunction() {
    ...
  }
  $seekme = true;
}
Your "parser" would return the secondlevelfunction whilst should return firstlevelfunction.

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.
User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post by neel_basu »

szaky wrote:That would return iamnotwhatyouareafter in the following snippet, while you seek the "mother" of $seekme:

Code: Select all

function iamnotwhatyouareafter() {
  ...
}
$seekme = true;
Ok, in that case the var $seekme is a global variable, not a local.
Before You mention that :) , here's another:
=========================================================

Code: Select all

$iamaglobalvariable = true;
function firstlevelfunction() {
  function secondlevelfunction() {
    ...
  }
  $seekme = true;
}
Your "parser" would return the secondlevelfunction whilst should return firstlevelfunction.

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.
Thanks.
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
}
Post Reply