Created
August 15, 2011 21:35
-
-
Save chucktrukk/1147928 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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');