Hello,
Is there a way to create functions dynamically in PHP as such:
<?php
$my_arr_conf = array(
'my_var' => 'This is my variable',
'your_var' => 'This is your variable'
);
// Some code here where I can create the function
// Maybe somehow with create_function(); ?
// I was hoping for something like overloading for procedural
// Just one function that would replace the following 2.
function my_var(){
static $value;
if(isset($value)){
return $value;
}
else{
$value = $my_arr_conf[__FUNCTION__];
return $value;
}
}
function you_var(){
static $value;
if(isset($value)){
return $value;
}
else{
$value = $my_arr_conf[__FUNCTION__];
return $value;
}
}
echo my_var();
echo your_var();
?>
Any help would be appreciated.
Thanks