get_defined_vars

array get_defined_vars(void) 

Fetch a list of all variables in the current scope.

Returns:

Associative array

Description:

get_defined_vars() returns an associative array that contains the names and values of all variables set in the current scope. The variable names are used as the key names, while the variable values are used as the array values.

Arrays and objects are rendered as nested arrays. See the following examples.

Note:

The array contains all variables set with the exception of the special variable $GLOBALS.

Version:

PHP 4.0.4+

Examples:

Display all global variables
<?php 
    print_r (get_defined_vars ()); 
?> 

Output is too long to display! 
Display all variables within an object
 <?php class foo { var $bar, $baz; function ...

Get PHP Functions Essential Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.