create_function with default parameter values?
Posted
by SoLoGHoST
on Stack Overflow
See other posts from Stack Overflow
or by SoLoGHoST
Published on 2010-05-01T08:40:54Z
Indexed on
2010/05/01
8:47 UTC
Read the original article
Hit count: 235
Ok, I'm looking into using create_function
for what I need to do, and I don't see a way to define default parameter values with it. Is this possible? If so, what would be the best approach for inputting the params into the create_function
function in php? Perhaps using addslashes
?
Well, for example, I have a function like so:
function testing($param1 = 'blah', $param2 = array())
{
if($param1 == 'blah')
return $param1
else
{
$notblah = '';
if (count($param2) >= 1)
{
foreach($param2 as $param)
$notblah .= $param;
return $notblah;
}
else
return 'empty';
}
}
Ok, so how would I use create_function
to do the same thing, adding the parameters and their default values?
The thing is, the parameters are coming from a TEXT file, as well as the function itself.
So, wondering on the best approach for this using create_function
and how exactly the string should be parsed.
Thanks :)
© Stack Overflow or respective owner