add object-compatible array modes

This commit is contained in:
Stanislav Malyshev 2008-11-24 18:10:36 +00:00
parent a9282f72a8
commit fce39ed9f7
2 changed files with 15 additions and 5 deletions

View File

@ -39,12 +39,14 @@ Type specifiers
instance of that class.
a - array (zval*)
A - array or object (zval *)
b - boolean (zend_bool)
C - class (zend_class_entry*)
d - double (double)
f - function or array containing php method call info (returned as
zend_fcall_info and zend_fcall_info_cache)
h - array (returned as HashTable*)
H - array or HASH_OF(object) (returned as HashTable*)
l - long (long)
o - object of any type (zval*)
O - object of specific type given by class entry (zval*, zend_class_entry)

View File

@ -295,7 +295,7 @@ static char *zend_parse_arg_impl(int arg_num, zval **arg, va_list *va, char **sp
{
char *spec_walk = *spec;
char c = *spec_walk++;
int return_null = 0;
int return_null = 0, obj_array = 0;
/* scan through modifiers */
while (1) {
@ -451,7 +451,8 @@ static char *zend_parse_arg_impl(int arg_num, zval **arg, va_list *va, char **sp
}
}
break;
case 'A':
obj_array = 1;
case 'a':
{
zval **p = va_arg(*va, zval **);
@ -459,14 +460,15 @@ static char *zend_parse_arg_impl(int arg_num, zval **arg, va_list *va, char **sp
*p = NULL;
break;
}
if (Z_TYPE_PP(arg) == IS_ARRAY) {
if (Z_TYPE_PP(arg) == IS_ARRAY || (Z_TYPE_PP(arg) == IS_OBJECT && obj_array != 0)) {
*p = *arg;
} else {
return "array";
}
}
break;
case 'H':
obj_array = 1;
case 'h':
{
HashTable **p = va_arg(*va, HashTable **);
@ -476,6 +478,11 @@ static char *zend_parse_arg_impl(int arg_num, zval **arg, va_list *va, char **sp
}
if (Z_TYPE_PP(arg) == IS_ARRAY) {
*p = Z_ARRVAL_PP(arg);
} else if(obj_array && Z_TYPE_PP(arg) == IS_OBJECT) {
*p = HASH_OF(*arg);
if(*p == NULL) {
return "array";
}
} else {
return "array";
}
@ -670,7 +677,8 @@ static int zend_parse_va_args(int num_args, char *type_spec, va_list *va, int fl
case 'o': case 'O':
case 'z': case 'Z':
case 'C': case 'h':
case 'f':
case 'f': case 'A':
case 'H':
max_num_args++;
break;