Skip to content

Instantly share code, notes, and snippets.

@chucktrukk
Created August 15, 2011 21:35
Show Gist options
  • Save chucktrukk/1147928 to your computer and use it in GitHub Desktop.
Save chucktrukk/1147928 to your computer and use it in GitHub Desktop.
<?php
function variable_name( &$var, $scope=false, $prefix='UNIQUE', $suffix='VARIABLE' ){
if($scope) {
$vals = $scope;
} else {
$vals = $GLOBALS;
}
$old = $var;
$var = $new = $prefix.rand().$suffix;
$vname = FALSE;
foreach($vals as $key => $val) {
if($val === $new) $vname = $key;
}
$var = $old;
return $vname;
}
<?php
// Another option
function vname(&$var, $scope=0)
{
$old = $var;
if (($key = array_search($var = 'unique'.rand().'value', !$scope ? $GLOBALS : $scope)) && $var = $old) return $key;
}
@chucktrukk
Copy link
Author

Maybe something else to use with

$skip=array('GLOBALS','_ENV','HTTP_ENV_VARS',
'_POST','HTTP_POST_VARS','_GET',
'HTTP_GET_VARS',
'_COOKIE',
'HTTP_COOKIE_VARS','_SERVER',
'HTTP_SERVER_VARS',
'_FILES','HTTP_POST_FILES',
'_REQUEST','HTTP_SESSION_VARS',
'_SESSION');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment