Skip to content

Commit fce39ed

Browse files
committed
add object-compatible array modes
1 parent a9282f7 commit fce39ed

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

README.PARAMETER_PARSING_API

+2
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@ Type specifiers
3939
instance of that class.
4040

4141
a - array (zval*)
42+
A - array or object (zval *)
4243
b - boolean (zend_bool)
4344
C - class (zend_class_entry*)
4445
d - double (double)
4546
f - function or array containing php method call info (returned as
4647
zend_fcall_info and zend_fcall_info_cache)
4748
h - array (returned as HashTable*)
49+
H - array or HASH_OF(object) (returned as HashTable*)
4850
l - long (long)
4951
o - object of any type (zval*)
5052
O - object of specific type given by class entry (zval*, zend_class_entry)

Zend/zend_API.c

+13-5
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ static char *zend_parse_arg_impl(int arg_num, zval **arg, va_list *va, char **sp
295295
{
296296
char *spec_walk = *spec;
297297
char c = *spec_walk++;
298-
int return_null = 0;
298+
int return_null = 0, obj_array = 0;
299299

300300
/* scan through modifiers */
301301
while (1) {
@@ -451,22 +451,24 @@ static char *zend_parse_arg_impl(int arg_num, zval **arg, va_list *va, char **sp
451451
}
452452
}
453453
break;
454-
454+
case 'A':
455+
obj_array = 1;
455456
case 'a':
456457
{
457458
zval **p = va_arg(*va, zval **);
458459
if (return_null) {
459460
*p = NULL;
460461
break;
461462
}
462-
if (Z_TYPE_PP(arg) == IS_ARRAY) {
463+
if (Z_TYPE_PP(arg) == IS_ARRAY || (Z_TYPE_PP(arg) == IS_OBJECT && obj_array != 0)) {
463464
*p = *arg;
464465
} else {
465466
return "array";
466467
}
467468
}
468469
break;
469-
470+
case 'H':
471+
obj_array = 1;
470472
case 'h':
471473
{
472474
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
476478
}
477479
if (Z_TYPE_PP(arg) == IS_ARRAY) {
478480
*p = Z_ARRVAL_PP(arg);
481+
} else if(obj_array && Z_TYPE_PP(arg) == IS_OBJECT) {
482+
*p = HASH_OF(*arg);
483+
if(*p == NULL) {
484+
return "array";
485+
}
479486
} else {
480487
return "array";
481488
}
@@ -670,7 +677,8 @@ static int zend_parse_va_args(int num_args, char *type_spec, va_list *va, int fl
670677
case 'o': case 'O':
671678
case 'z': case 'Z':
672679
case 'C': case 'h':
673-
case 'f':
680+
case 'f': case 'A':
681+
case 'H':
674682
max_num_args++;
675683
break;
676684

0 commit comments

Comments
 (0)