note 106143 deleted from function.func-get-args by peehaa

From: Date: Mon, 08 Apr 2019 06:12:30 +0000
Subject: note 106143 deleted from function.func-get-args by peehaa
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-210554@lists.php.net to get a copy of this message
Note Submitter: red ---- 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']); ?>

« previous php.notes (#210554) next »