Re: Q. zend_parse_parameters() - allow grouping of optional parameters.
| From: | Scott MacVicar | Date: | Wed, 10 Oct 2007 09:55:20 +0000 |
| Subject: | Re: Q. zend_parse_parameters() - allow grouping of optional parameters. | ||
| References: | 1 | Groups: | php.internals php.internals |
| Request: | Send a blank email to internals+get-32720@lists.php.net to get a copy of this message | ||
if (ZEND_NUM_ARGS() != 3 && ZEND_NUM_ARGS() != 6 && ZEND_NUM_ARGS() != 7) {
WRONG_PARAM_COUNT;
}
Will let you check that there are 3, 6 and 7 parameters.
Scott
Richard Quadling wrote:
> Hi.
>
> From what I understand about the argument list for
> zend_parse_parameters(), you separate optional parameters from
> mandatory ones using pipe (|).
>
> e.g.
>
> if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll|llll", &m,
> &d, &y, &h, &n, &s, &ms) == FAILURE) {
>
> In the above example, this says that there are 3 mandatory parameters
> and upto 4 optional parameters.
>
> The prototype for this looks like ...
>
> proto bool myExampleDateFunc(int month, int day, int year, [int hour
> [, int min [, int sec [,int msec]]]])
>
> Is there a way to make the prototype ...
>
> proto bool myExampleDateFunc(int month, int day, int year, [int hour,
> int min, int sec[, int msec]])
>
> So, making this function accept 3 or 6 or 7 parameters only.
>
> I'm guessing not, but I'm guessing. I think this has to be checked using ...
>
> switch (ZEND_NUM_ARGS()) {
>
> after parsing the parameters and generate an error for ZEND_NUM_ARGS = 4 or 5.
>
> Regards,
>
> Richard.
>