zend_parse_parameters() improvements
| From: | Gustavo Lopes | Date: | Wed, 18 Jul 2012 21:05:45 +0000 |
| Subject: | zend_parse_parameters() improvements | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-61440@lists.php.net to get a copy of this message | ||
Some deficiencies in zpp have been constrai
ning the implementation of common scenarios such as 'allow integer or NULL'* or the more general 'allow different types for an argument'**.
So I propose the changes in this branch:
https://github.com/cataphract/php-src/compare/zpp_improv
Please see the commit messages for the rationale.
*Example:
https://github.com/php/php-src/pull/13
(again more recently on
https://github.com/php/php-src/pull/133 )
**
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
}
}
--
Gustavo Lopes