note 64599 added to function.func-get-args
| From: | damien_ at hotmail dot com | Date: | Wed, 19 Apr 2006 05:47:53 +0000 |
| Subject: | note 64599 added to function.func-get-args | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-108494@lists.php.net to get a copy of this message | ||
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);
}
----
Server IP: 193.27.201.10 (proxied: 193.27.201.10 1.0 www1.shellkonto.se:3128 (squid/2.5.STABLE4))
Probable Submitter: 81.225.190.59
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.func-get-args.php
Edit -- http://master.php.net/note/edit/64599
Del: integrated -- http://master.php.net/note/delete/64599/integrated
Del: useless -- http://master.php.net/note/delete/64599/useless
Del: bad code -- http://master.php.net/note/delete/64599/bad+code
Del: spam -- http://master.php.net/note/delete/64599/spam
Del: non-english -- http://master.php.net/note/delete/64599/non-english
Del: in docs -- http://master.php.net/note/delete/64599/in+docs
Del: other reasons-- http://master.php.net/note/delete/64599
Reject -- http://master.php.net/note/reject/64599
Search -- http://master.php.net/manage/user-notes.php