How to get all variables defined in the current scope/symbol table?

前端 未结 2 1708
广开言路
广开言路 2020-12-13 05:54

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(         


        
相关标签:
2条回答
  • 2020-12-13 06:31

    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.

    0 讨论(0)
  • 2020-12-13 06:35

    get_defined_vars() does exactly what you want.

    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.

    >>> function test($foo) { print_r(get_defined_vars()); }
    >>> test('bar');
    Array
    (
        [foo] => bar
    )
    
    0 讨论(0)
提交回复
热议问题