Hi all,
i have taken from net script that it has curriying function which itself return function.
But i dont understand why before \$arg is added backslash. the same as on lines 10, 13, 19 and so on.

function add($a, $b)
		 return $a + $b;
	function _curry( $function, $num_args )
   	   return create_function('', "
            \$args = func_get_args();
            // Execute the function if the right number of arguments were passed
            if( count(\$args)>=$num_args )
                return call_user_func_array('$function', \$args);
            // Export the function arguments as executable PHP code
            \$args = var_export(\$args, 1);
            // Return a new function with the arguments stored otherwise
            return create_function('','
                \$a = func_get_args();
                \$z = ' . \$args . ';
                \$a = array_merge(\$z,\$a);
                return call_user_func_array(\'$function\', \$a);
	$func =_curry('add', 2);

Thanks for attention

Recommended Answers

All 2 Replies

From: http://php.net/manual/en/function.create-function.php

Usually these parameters will be passed as single quote delimited strings. The reason for using single quoted strings, is to protect the variable names from parsing, otherwise, if you use double quotes there will be a need to escape the variable names, e.g. \$avar.

bye :)

Thanks for help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.