Code: Select all
function parse_me_on_the_fly () {
global $skin;
//how many damn ages do we have?
$args_num = func_num_args();
$arg_list = func_get_args();
//name and set...
$group_name = $arg_list[0];
$name = $arg_list[1];
//get argnames
$args = $skin[$group_name][$name]['args'];
//remove spaces
if ($args) {
$args_l = strtr($args, ' ', '');
$args_l = explode(',', $args_l);
}
//rest...
$sweet_args = array();
if ($args_l) {
$count = count($args_l);
for ($i = 0; $i < $count; $i++) {
$sweet_args[] = '$arg_list['.($i+2).']';
}
$sweet_args = implode(',', $sweet_args);
}
// can we get it done yet?
$func = create_function ($args, $skin[$group_name][$name]['content']);
//got it? then do it!
return eval("return \$func($sweet_args);");
} //parse_me_on_the_flyCode: Select all
Parse error: parse error, unexpected T_ARRAY_CAST in /srv/www/htdocs/web172/html/sub/core/func/template.php(88) : eval()'d code on line 1Here's a short description of what above function does, just to cleat things up a bit... What this function is doing is:
- accepting x arguments. First two are mandatory, rest is optional. They are captured to $arg_list.
- the first two arguments are needed to locate data within $skin array. Using that info we are able to import a string of arguments $args and a body of a function as another string
- those two imported bits of data are then used to create a function stored in $func
- next we want to catch all the additional arguments coming into the main function. To use them as arguments of the function we just created we have to convert the additional arguments in $arg_list to a string of argument names, making ie "arg_list[2], arg_list[3]"
- then we use eval to call created function with the additional arguments.
All this is because the created function arguments as well as body is made somewhere else, and we want to parse them into a function and run with the arguments that are passed into the parent function [parse_me_on_the_fly()]. We don't know how many arguments there will be, hence the need for fancy stuff.
The qestion obviously is why am I getting those type cast errors, and how to fix that ^_^