I found this code online and i want to understand it, i have read the php documentation but i have found out that the php programming community offers better explanations

PHP Code:
function mysql_safe_query($query) { 
   $args = array_slice(func_get_args(),1); 
   $args = array_map('mysql_safe_string',$args); 
   return mysql_query(vsprintf($query,$args)); 
   }  

I figure the function isn't a builtin php function.array_slice returns a sequence of elements from the array func_get_args with an offset of 1.

I looked up func_get_args and it's supposed to return a copy of the given element(array? object)?? and I guess vsprintf returns a formatted string, removing the string quotations '' ??

Don’t look at it , it is a very bad coding example , the title of it could be “things you should never do”. In OOP PHP you never have to deal with function (few exceptions as fatal error calling functions)… The laughing part is func_get_args() , if you don’t know what arguments you pass to the method / function then you have problem. There are more on that as the calling function of mysql_safe_string that is made it wide open for anybody … PHP have solved that with many features as PDO … (there are others as well but I stick to PDO)… Bottom line that is a really lame code and everyone that suggest that one should be shamed.

i realize that now, reading up on PDO

Be a part of the DaniWeb community

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