问题
Is there a quick and concise way of finding the declaration of a global variable in PHP?
If we are dealing with a large codebase where the global variable may be referenced in many different files:
- Using
ctags
to jump to declaration takes you to the local statement where the global is brought into scope in the current file - Searching for
global $foo
usinggrep
orack
results in a list of files where the global was brought into scope, but not the exact declaration of the global variable
Is there any tool/vim plugin/etc that will tell you exactly where the global is being declared for the first time?
Update: I guess you could set a watch breakpoint and look for the first access to the variable. Unfortunately, this type of breakpoint is not yet supported in Xdebug, so for my particular setup, it wouldn't work.
回答1:
Are you a Unix-based OS?
I usually do something like grep -rn 'global $myvar' .
in the top-level directory. This does a recursive search of files in the current directory for the declaration.
Or, if you want to get fancy you can search for only PHP files:
grep -rn --include '*.php' 'global $myvar' .
来源:https://stackoverflow.com/questions/18061788/find-declaration-of-a-global-variable-in-php