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

PhpDebuggingScope

Php Problem Overview


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.

Php Solutions


Solution 1 - Php

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.

Solution 2 - Php

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
)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAlan StormView Question on Stackoverflow
Solution 1 - PhptroelsknView Answer on Stackoverflow
Solution 2 - PhpPaige RutenView Answer on Stackoverflow