Skip to content

Commit 3878414

Browse files
committed
Support named arguments and return failure on exception
1 parent 732a7c4 commit 3878414

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

Zend/zend_API.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,21 +1846,31 @@ ZEND_API zend_result object_init_ex(zval *arg, zend_class_entry *class_type) /*
18461846
}
18471847
/* }}} */
18481848

1849-
ZEND_API zend_result object_init_with_constructor(zval *arg, zend_class_entry *class_type, uint32_t param_count, zval *params) /* {{{ */
1849+
ZEND_API zend_result object_init_with_constructor(zval *arg, zend_class_entry *class_type, uint32_t param_count, zval *params, HashTable *named_params) /* {{{ */
18501850
{
18511851
zend_result status = _object_and_properties_init(arg, class_type, NULL);
18521852
if (UNEXPECTED(status == FAILURE)) {
18531853
return FAILURE;
18541854
}
1855-
/* A constructor does not return a value */
1856-
zend_call_known_instance_method(
1855+
/* A constructor does not return a value, however if an exception is thrown
1856+
* zend_call_known_function() will set the retval to IS_UNDEF */
1857+
zval retval;
1858+
ZVAL_UNDEF(&retval);
1859+
zend_call_known_function(
18571860
class_type->constructor,
18581861
Z_OBJ_P(arg),
1862+
class_type,
18591863
/* retval */ NULL,
18601864
param_count,
1861-
params
1865+
params,
1866+
named_params
18621867
);
1863-
return SUCCESS;
1868+
if (Z_TYPE(retval) == IS_UNDEF) {
1869+
return FAILURE;
1870+
} else {
1871+
zval_ptr_dtor(&retval);
1872+
return SUCCESS;
1873+
}
18641874
}
18651875
/* }}} */
18661876

Zend/zend_API.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ ZEND_API const char *zend_get_type_by_const(int type);
537537
#define array_init_size(arg, size) ZVAL_ARR((arg), zend_new_array(size))
538538
ZEND_API void object_init(zval *arg);
539539
ZEND_API zend_result object_init_ex(zval *arg, zend_class_entry *ce);
540-
ZEND_API zend_result object_init_with_constructor(zval *arg, zend_class_entry *class_type, uint32_t param_count, zval *params);
540+
ZEND_API zend_result object_init_with_constructor(zval *arg, zend_class_entry *class_type, uint32_t param_count, zval *params, HashTable *named_params);
541541
ZEND_API zend_result object_and_properties_init(zval *arg, zend_class_entry *ce, HashTable *properties);
542542
ZEND_API void object_properties_init(zend_object *object, zend_class_entry *class_type);
543543
ZEND_API void object_properties_init_ex(zend_object *object, HashTable *properties);

0 commit comments

Comments
 (0)