note 71610 added to language.variables.variable
| From: | lucile dot fievet at eufar dot net | Date: | Thu, 07 Dec 2006 15:21:34 +0000 |
| Subject: | note 71610 added to language.variables.variable | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-120378@lists.php.net to get a copy of this message | ||
This is an example of dynamic code, with variable global scope and
variable variable used in array parsing and function calling:
http://toto.php?num=127
// an example of accepted get var
$arrGet = array('num');
// an example of accepted cookie var
$arrCook = array('myid', 'myweb', 'whatever', 'bof');
//function to get cookies
function cookieGet($varname){
if(isset($_COOKIE[$varname])) return $_COOKIE[$varname];
}
// list of function and array to get var by different means
$listVarArrGetFunc = array('arrGet' => 'urlGet',
'arrPost' => 'postGet',
'arrSess' => 'sessionGet',
'arrCook' => 'cookieGet',
'arrFileUp' => 'fileUploadGet'
);
// dynamic function to get var by all means
function byAllMeansGet($varname){
global $listVarArrGetFunc;
foreach ($listVarArrGetFunc as $arrn => $fctn){
global $$arrn, $$fctn;
if($arrn!='arrGlob'){
$arrayX = $$arrn;
//echo "<br><br> arrn : $arrn -> $$arrn -> $arrayX ";
//echo "fctn : $fctn <br>";
/* **************************************************************
* arrn : arrCook -> $arrCook -> Array fctn : cookieGet *
*****************************************************************/
foreach ($arrayX as $varn){
//echo " varn : $varn -> ";
$$varn = $fctn($varn);
//echo $$varn . " ";
/**********************************************************
varn : myid -> plop varn : myweb -> toto
varn : whatever -> hum varn : bof ->
************************************************************/
if($varname!="" && $varn==$varname)
return $$varn;
if($varname=="" && $varn!=""){
$GLOBALS[$varn]=$$varn;
}
}
}
}
}
//$num = byAllMeansGet("num");
byAllMeansGet("");
echo "num :" . $num;
/**********************************************
num: 127
***********************************************/
----
Server IP: 66.163.161.117
Probable Submitter: 137.129.13.90 (proxied: ICAP/1.0 172.31.200.4)
----
Manual Page -- http://www.php.net/manual/en/language.variables.variable.php
Edit -- https://master.php.net/note/edit/71610
Del: integrated -- https://master.php.net/note/delete/71610/integrated
Del: useless -- https://master.php.net/note/delete/71610/useless
Del: bad code -- https://master.php.net/note/delete/71610/bad+code
Del: spam -- https://master.php.net/note/delete/71610/spam
Del: non-english -- https://master.php.net/note/delete/71610/non-english
Del: in docs -- https://master.php.net/note/delete/71610/in+docs
Del: other reasons-- https://master.php.net/note/delete/71610
Reject -- https://master.php.net/note/reject/71610
Search -- https://master.php.net/manage/user-notes.php