Chcem sa spytat, ci naaaaaahodou neexistuje pod PHP nejaka funkcia, ktora je schopna vydumpovat do lubovolneho suboru, obsah vsetkych inicializovanych premennych v takom tvare, aby ich bolo mozne znova v inom skripte jednoducho "includovat" z tohoto suboru.
Viem, ze sa to da spravit, len ci naahodou nie je nieco taketo aj v PHPcku.
Dik.
Existuje pod PHP takato funkcia?...
-
audiotrack
VIP
- Príspevky: 25958
- Registrovaný: 09 sep 2005, 18:39
- Kontaktovať používateľa:
Tak ziskanie premennych/hodnot som myslim videl tu:
Kód: Vybrať všetko
<?php
/**
* @desc works out the variables in the current scope(from where function was called).
* Returns an array with variable name as key and vaiable value as value
* @param $varList: variables returned by get_defined_vars() in desired scope.
* $excludeList: variables to be excluded from the list.
* @return array
*/
function getDefinedVars($varList, $excludeList)
{
$temp1 = array_values(array_diff(array_keys($varList), $excludeList));
$temp2 = array();
while (list($key, $value) = each($temp1)) {
global $$value;
$temp2[$value] = $$value;
}
return $temp2;
}
/**
* @desc holds the variable that are to be excluded from the list.
* Add or drop new elements as per your preference.
* @var array
*/
$excludeList = array('GLOBALS', '_FILES', '_COOKIE', '_POST', '_GET', 'excludeList');
//some dummy variables; add your own or include a file.
$firstName = 'kailash';
$lastName = 'Badu';
$test = array('Pratistha', 'sanu', 'fuchhi');
//get all variables defined in current scope
$varList = get_defined_vars();
//Time to call the function
print "<pre>";
print_r(getDefinedVars($varList, $excludeList));
print "</pre>";
?>
-
mastermind
VIP
- Príspevky: 4810
- Registrovaný: 09 feb 2005, 13:17
priamo jedna funkcia na to neexistuje, ale velmi jednoducho to docielis pomocou funkcii:
get_defined_vars
var_export
eval
get_defined_vars
var_export
eval
Kód: Vybrať všetko
http://sk2.php.net/manual/en/function.get-defined-vars.php
http://sk2.php.net/manual/en/function.var-export.php
http://sk2.php.net/manual/en/function.eval.php