note 64599 deleted from function.func-get-args by bjori
| From: | bjori@php.net | Date: | Tue, 25 Apr 2006 19:04:14 +0000 |
| Subject: | note 64599 deleted from function.func-get-args by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-109664@lists.php.net to get a copy of this message | ||
Note Submitter: damien_ at hotmail dot com
----
I had a place where I needed a single way to call functions with any number of arguments and to come
around the thing with default args I did like this.
(This specific function was to retrive som stats).
Then I could have a loop that looped all functions and was able to call them all based on a decided
pattern (in this case they all started with startdate and enddate and then they could have any
number of aditional args.)
function statNewsWindow()
{
$old_error_report_level = error_reporting(0);
// Arguments
$startDate = (func_get_arg(0) != FALSE) ? func_get_arg(0) : DEFAULT_STARTDATE;
$endDate = (func_get_arg(1) != FALSE) ? func_get_arg(1) : DEFAULT_ENDDATE;
$partner = (func_get_arg(2) != FALSE) ? func_get_arg(2) : NULL;
$user = (func_get_arg(3) != FALSE) ? func_get_arg(3) : NULL;
$clicked = (func_get_arg(4) != FALSE) ? func_get_arg(4) : NULL;
error_reporting($old_error_report_level);
// get all users from tecknat_posts that
$rc = GetSQLObjects("SELECT COUNT(*) AS num FROM statsys_newswindow
WHERE date >= '$startDate' AND date <= '$endDate'" .
($partner != NULL ? " AND partnerId = $partner" : "") . ($user != NULL ? "
AND userId = $user" : "") . ($clicked != NULL ? " AND clicked=1" : "
clicked=0"));
return (count($rc) == 1 && empty($rc[0]->region)? $rc[0]->num : $rc);
}