note 83375 added to language.variables

From: Date: Thu, 22 May 2008 18:07:57 +0000
Subject: note 83375 added to language.variables
Groups: php.notes 
Request: Send a blank email to php-notes+get-139624@lists.php.net to get a copy of this message
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. ---- Server IP: 208.69.120.35 Probable Submitter: 66.186.179.99 ---- Manual Page -- http://www.php.net/manual/en/language.variables.php Edit -- https://master.php.net/note/edit/83375 Del: integrated -- https://master.php.net/note/delete/83375/integrated Del: useless -- https://master.php.net/note/delete/83375/useless Del: bad code -- https://master.php.net/note/delete/83375/bad+code Del: spam -- https://master.php.net/note/delete/83375/spam Del: non-english -- https://master.php.net/note/delete/83375/non-english Del: in docs -- https://master.php.net/note/delete/83375/in+docs Del: other reasons-- https://master.php.net/note/delete/83375 Reject -- https://master.php.net/note/reject/83375 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#139624) next »