954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Backslashes before variable in PHP

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;
		}
		$az="";
	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

azegurb
Posting Whiz in Training
244 posts since Sep 2009
Reputation Points: 11
Solved Threads: 2
 

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 :)

cereal
Master Poster
709 posts since Aug 2007
Reputation Points: 214
Solved Threads: 120
 

Thanks for help

azegurb
Posting Whiz in Training
244 posts since Sep 2009
Reputation Points: 11
Solved Threads: 2
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You