note 106143 added to function.func-get-args
| From: | red at osu1 dot php dot net | Date: | Thu, 13 Oct 2011 20:16:45 +0000 |
| Subject: | note 106143 added to function.func-get-args | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-183865@lists.php.net to get a copy of this message | ||
I had to pass variable length arguments from one function to another. It seems the only way of doing
this is to use call_user_func_array.
<?php
function query(/*query [, $arg1...$argN]*/){
$query = call_user_func_array('replaceAndClean', func_get_args());
$result = mysql_query($query);
return $result;
}
function replaceAndClean(/*query [, $arg1...$argN]*/){
$args = func_get_args();
if(count($args) == 1){
return $args[0];
}
$query = array_shift($args);
return vsprintf($query, array_map('mysql_real_escape_string', $args));
}
?>
Example:
<?php
// unsave call
query("SELECT FROM foo where bar='".$_POST['bar']."'");
// save call
query("SELECT FROM foo where bar='%d'", $_POST['bar']);
?>
----
Server IP: 69.147.83.197
Probable Submitter: 213.196.211.172
----
Manual Page -- http://www.php.net/manual/en/function.func-get-args.php
Edit -- https://master.php.net/note/edit/106143
Del: integrated -- https://master.php.net/note/delete/106143/integrated
Del: useless -- https://master.php.net/note/delete/106143/useless
Del: bad code -- https://master.php.net/note/delete/106143/bad+code
Del: spam -- https://master.php.net/note/delete/106143/spam
Del: non-english -- https://master.php.net/note/delete/106143/non-english
Del: in docs -- https://master.php.net/note/delete/106143/in+docs
Del: other reasons-- https://master.php.net/note/delete/106143
Reject -- https://master.php.net/note/reject/106143
Search -- https://master.php.net/manage/user-notes.php