33

Is it possible to list out all the Global Variable. Such , as to print all session variable we can use print_r($_SESSION); as the same way, if i want to know how many Global variables are define in my site. is it possible? Please Help.

I need the list which can show me all the Global variables List in PHP.

Hemi
  • 829
  • 1
  • 9
  • 12

5 Answers5

39

Yes, PHP $GLOBALS array will show you.

<?php

echo "<pre>";
print_r($GLOBALS);
echo "</pre>";
Jordan Arsenault
  • 7,100
  • 8
  • 53
  • 96
9

To get names of all global variables do this:

array_keys($GLOBALS)

More docs:

Tadeck
  • 132,510
  • 28
  • 152
  • 198
3

$GLOBALS — References all variables available in global scope also check this PHP global or $GLOBALS here you find many important and useful thing about $GLOBALS

Community
  • 1
  • 1
NullPoiиteя
  • 56,591
  • 22
  • 125
  • 143
2

The reserved $GLOBALS variable is an array containing all global variables.

In the array, the keys are variable names and the values are variable values.

FThompson
  • 28,352
  • 13
  • 60
  • 93
2

Well, there does exist a $GLOBALS variable in PHP.

But you can't do a var_export() on it. It'll lead to an error like: Nesting level too deep - recursive dependency?

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
  • If you **DO WANT** to have a [`var_export`](http://php.net/manual/en/function.var-export.php) then [check this](http://php.net/manual/en/function.var-export.php#100302) – hjpotter92 Sep 19 '12 at 07:28