Em Thu, 19 Jul 2012 01:11:38 +0200, Stas Malyshev <smalys...@sugarcrm.com> escreveu:

Example:
http://lxr.php.net/xref/PHP_TRUNK/ext/intl/timezone/timezone_methods.cpp#143
In this case, NULL, int and string are allowed. This would become much
simpler:

if (arg == NULL || Z_TYPE_PP(arg) == IS_NULL) {
     se = TimeZone::createEnumeration();
} else {
     long l;
     char *s;
     int s_len;
     if (zend_parse_parameter(ZEND_PARSE_PARAMS_QUIET,
             1 TSRMLS_DC, arg, "l", &l) == SUCCESS) {
         TimeZone::createEnumeration((int32_t) l);
     } else if (zend_parse_parameter(ZEND_PARSE_PARAMS_QUIET,
             1 TSRMLS_DC, arg, "s", &s, &s_len) == SUCCESS) {
         TimeZone::createEnumeration(s);
     } else {
         //raise errror
     }

Wait, didn't you say applying zpp to arg as l, then as s would change
it? Or your function doesn't change it?

Yes, the zval is potentially changed in both calls (that's why the argument is passed with double indirection). But this is not a problem here (in fact, it simplifies resource management -- since the second zend_parse_parameter() changes the zval in the stack, the engine can reclaim the zval and string automatically when the function returns).

There's to argument if its processing fails. zend_parse_parameters() (plural) changes the arguments only until it fails. Yes, whether an argument is changed or not depends on its position relative to the failing argument.

Since zend_parse_parameter() takes only one argument this is not a problem -- supposedly, you call zend_parse_parameter() successfully only once. In any case, you can always copy the zval yourself.

In any case, I think giving access to single-parameter parsing is a good
idea and allows functions to implement complex cases in more consistent
manner - right now I know there are some functions that return different
error messages than zpp does when they parse arguments, for example -
this can be fixes.


--
Gustavo Lopes

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to