]> granicus.if.org Git - php/commitdiff
add object-compatible array modes
authorStanislav Malyshev <stas@php.net>
Mon, 24 Nov 2008 18:10:36 +0000 (18:10 +0000)
committerStanislav Malyshev <stas@php.net>
Mon, 24 Nov 2008 18:10:36 +0000 (18:10 +0000)
README.PARAMETER_PARSING_API
Zend/zend_API.c

index d2e47eb42167250e42be58e68a9a595026b68efb..530b2b560d7e0c9fa38583d489115ee1fff97848 100644 (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)
index 23a3dbbe31b962365994d2ee4338e9dbb96eda26..0b505d933ae98e345facd1b72335bb12a706b7cf 100644 (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;