If you need a 1: 1 function mapping, this works, it makes backtracking a bit unpleasant, but it works
class DB { public static function escape() { $args = func_get_args(); return call_user_func_array('mysql_real_escape_string', $args ); } } DB::escape( $foo );
Now I used the func_get_args / call trick here for only one reason:
This notation should work with any function .
However, it would be more optimal to simply link it directly
class DB { public static function escape($string) { return mysql_real_escape_string( $string ); } }
And there is no good reason to delete slashes unless you have this terrible "function" in php that activates input with an automatic slash.
class DB { public static function un_gpc($string) { if( get_magic_quotes_gpc() === 1 ) { return stripslashes( $string ); } return $string; } public static function escape($string, $quote=false) { if( !$quote ) { return mysql_real_escape_string( $string ); } return '"' . self::escape( $string ) . '"'; } public static function escape_gpc( $string , $quote = false ) { return self::escape( self::un_gpc( $string ), $quote); } public static function get( $string , $quote = true ) { return self::escape_gpc( $_GET[$string] , $quote ); } }
source share