Is there a way to get user declared variables in PHP?

php

Solution

How about a little array manipulation?

$testVar = 'foo';
// list of keys to ignore (including the name of this variable)
$ignore = array('GLOBALS', '_FILES', '_COOKIE', '_POST', '_GET', '_SERVER', '_ENV', 'ignore');
// diff the ignore list as keys after merging any missing ones with the defined list
$vars = array_diff_key(get_defined_vars() + array_flip($ignore), array_flip($ignore));
// should be left with the user defined var(s) (in this case $testVar)
var_dump($vars);

// Result: 
array(1) {
    ["testVar"]=>string(3) "foo"
}

Problem

get_defined_vars is about to (citation): return a multidimensional array containing a list of all defined variables, be them environment, server or user-defined variables well, for my debugging task, I need only those user-defined. Is there php-built-in or supplement function? EDIT: Ok I didn't made clear what exactly I was after, here is little example: ``` <?php /* this script is included, and I don't have info about how many scripts are 'above' and 'bellow' this*/ //I'm at line 133 $user_defined_vars = get_user_defined_vars(); //$user_defined_vars should now be array of names of user-defined variables //what is the definition of get_user_defined_vars()? ?> ```

Original source