Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 796
Alan Storm Avatar asked Apr 04 '09 21:04

Alan Storm


People also ask

How will you get the information about all variables that are currently in scope?

You can see scopes and their variables in [[Scopes]] , even closure scopes using console. dir() . It shows you the variables in "[[Scopes]] > Closure", "[[Scopes]] > Global" and even "[[Scopes]] > Script" if the page have scripts reachable. Even with nested closures you can see the nested scopes.

What kind of variable information might be stored in the symbol table?

Symbol Table is an important data structure created and maintained by the compiler in order to keep track of semantics of variables i.e. it stores information about the scope and binding information about names, information about instances of various entities such as variable and function names, classes, objects, etc.

What is scoping in symbol table?

These scope rules need a more complicated organization of symbol table than a list of associations between names and attributes. Tables are organized into stack and each table contains the list of names and their associated attributes. Whenever a new block is entered then a new table is entered onto the stack.


1 Answers

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.

like image 163
troelskn Avatar answered Sep 24 '22 01:09

troelskn