Re: zend_parse_parameters() improvements

From: Date: Wed, 18 Jul 2012 22:31:48 +0000
Subject: Re: zend_parse_parameters() improvements
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-61444@lists.php.net to get a copy of this message
On Wed, Jul 18, 2012 at 11:05 PM, Gustavo Lopes <glopes@nebm.ist.utl.pt> wrote: > 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 > } > } +1 The long/null issue comes up every once in a while. This is really useful. Nikita

« previous php.internals (#61444) next »