note 83375 deleted from language.variables by danbrown

From: Date: Sun, 20 Jul 2008 15:55:56 +0000
Subject: note 83375 deleted from language.variables by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-142141@lists.php.net to get a copy of this message
Note Submitter: ned at wgtech dot com ---- The function given in lower posts: function var_name(&$var, $scope=0) { if (($old = $var) && ($key = array_search($var = 'unique'.rand().'value', !$scope ? $GLOBALS : $scope)) && (($var = $old) || true)) return $key; } has a nasty problem. If array_search fails the (($var=$old)||true) never gets evaluated, and rightly so, permanently changing the value of $var to 'unique#####value'. How to fail the function: $z=1; var_name($z,array(1)); Easily fixed by adding an else: function var_name(&$var, $scope=false) { if ((($old=$var)||true)&&($key = array_search($var = 'unique'.rand().'value', !$scope ? $GLOBALS : $scope)) && (($var = $old) || true)) return $key; else $var=$old;return false; } All better.

« previous php.notes (#142141) next »