0

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 '' ??

2
Contributors
3
Replies
25
Views
3 Years
Discussion Span
Last Post by rhodoscoder
1

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.