Find declaration of a global variable in PHP

本秂侑毒 提交于 2019-11-28 08:26:38

问题


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 using grep or ack 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!