在PHP中查找全局变量的声明

在PHP中查找全局变量的声明

本文介绍了在PHP中查找全局变量的声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种快速而简洁的方法来查找PHP中全局变量的声明?



如果我们正在处理一个大型代码库,其中全局变量可能是在许多不同的文件中引用:


  • 使用 ctags
  • 使用搜索全局$ foo 全局变为当前文件的局部语句
  • grep ack 会生成全局范围内的文件列表,但不包含全局变量的确切声明


是否有任何工具/ vim插件/ etc会告诉你第一次声明全局的位置?






更新:我猜你可以设置观察断点并寻找第一次访问变量。不幸的是,这种类型的断点在Xdebug中尚不支持,所以对于我的特殊设置,它不起作用。

你是基于Unix的操作系统吗?



我通常做类似于 grep -rn'global $ myvar'。



在顶层目录中。这可以为当前目录中的文件进行递归搜索。



或者,如果您想要获得幻想,您只能搜索PHP文件:



grep -rn --include'* .php''global $ myvar'。


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.

解决方案

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' .

这篇关于在PHP中查找全局变量的声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 01:18