如何获取当前范围/符号表中定义的所有变量?
PHP 中是否有函数和/或对象和/或扩展可以让您查看当前作用域中定义的所有变量?类似的东西:
Is there a function and/or object and/or extension in PHP that will let you view all the variables defined in the current scope? Something like:
var_export($GLOBALS)
但只显示当前符号表中的变量.
but only showing variables in the current symbol table.
推荐答案
get_defined_vars
此函数返回一个多维数组,其中包含所有定义变量的列表,包括环境变量、服务器变量或用户定义变量,在 get_defined_vars()
的范围内叫.
This function returns a multidimensional array containing a list of all defined variables, be them environment, server or user-defined variables, within the scope that
get_defined_vars()
is called.
相关文章