get_defined_vars() returns all variables - locally defined vars and global vars (well actually only super globals). If you need local vars only - for example you need to get variables from a file - let's say config.php and you don't want a missing value to be replaced with a global defined somewhere else.
<?php
function removeGlobals(array $localVars) {
return array_diff_key($localVars, $GLOBALS);
}
define('CONFIG_FILE_PATH', '/path/to/config.php');
function readConfig() {
require CONFIG_FILE_PATH;
$config = removeGlobals(get_defined_vars());
return $config;
}
?>