For this type of situation, you could equally go with something like:
zval *val;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "n", &val) == FAILURE)
{ RETURN_NULL(); }
Where the 'n' type looks for a numeric value: IS_LONG/IS_DOUBLE kept as is,
IS_STRING/IS_OBJECT (with toString() behavior) converted to
IS_LONG/IS_DOUBLE if possible, anything else an error.
And for methods where a non-numeric string makes sense:
'N' type would not error on other types, but pass them through. It would
differ from the 'z' type only in that IS_STRING/IS_OBJECT would attempt to
convert to IS_LONG/IS_DOUBLE if possible, but unlike 'n' it wouldn't panic.
-Sara
On Wed, Jul 18, 2012 at 2:05 PM, Gustavo Lopes <[email protected]>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<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<https://github.com/php/php-src/pull/13>
> (again more recently on
> https://github.com/php/php-**src/pull/133<https://github.com/php/php-src/pull/133>)
> **
> Example: http://lxr.php.net/xref/PHP_**TRUNK/ext/intl/timezone/**
> timezone_methods.cpp#143<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
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>