List all PHP variables

Salman A picture Salman A · Feb 24, 2011 · Viewed 66k times · Source

Is it possible to dump all global variables in a PHP script? Say this is my code:

<?php
$foo = 1;
$bar = "2";
include("blah.php");
dumpall();
// displays $foo, $bar and all variables created by blah.php

Also, is it possible to dump all defined constants in a PHP script.

Answer

nico picture nico · Feb 24, 2011

Use get_defined_vars and/or get_defined_constants

$arr = get_defined_vars();
print_r($arr);