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

Is there a function in PHP and / or an object and / or extension that will allow you to view all the variables defined in the current scope? Something like:

var_export($GLOBALS) 

but only displaying variables in the current symbol table.

+53
scope debugging php
Apr 04 '09 at 21:30
source share
2 answers

get_defined_vars

This function returns a multidimensional array containing a list of all defined variables, be it the environment, server, or user variables, within the scope from which get_defined_vars() called.

+61
Apr 04 '09 at 21:39
source share

get_defined_vars () does exactly what you want.

This function returns a multidimensional array containing a list of all defined variables, be it the environment, server, or user variables, within the scope from which get_defined_vars () is called.

 >>> function test($foo) { print_r(get_defined_vars()); } >>> test('bar'); Array ( [foo] => bar ) 
+22
Apr 04 '09 at 21:39
source share



All Articles