Skip to content

Commit f5c8ecb

Browse files
committed
Zend: Add object_init_with_constructor() API
This will instantiate the object and execute its constructor with the given parameters.
1 parent 5b35740 commit f5c8ecb

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

Zend/zend_API.c

+18
Original file line numberDiff line numberDiff line change
@@ -1846,6 +1846,24 @@ 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) /* {{{ */
1850+
{
1851+
zend_result status = _object_and_properties_init(arg, class_type, NULL);
1852+
if (UNEXPECTED(status == FAILURE)) {
1853+
return FAILURE;
1854+
}
1855+
/* A constructor does not return a value */
1856+
zend_call_known_instance_method(
1857+
class_type->constructor,
1858+
Z_OBJ_P(arg),
1859+
/* retval */ NULL,
1860+
param_count,
1861+
params
1862+
);
1863+
return SUCCESS;
1864+
}
1865+
/* }}} */
1866+
18491867
ZEND_API void object_init(zval *arg) /* {{{ */
18501868
{
18511869
ZVAL_OBJ(arg, zend_objects_new(zend_standard_class_def));

Zend/zend_API.h

+1
Original file line numberDiff line numberDiff line change
@@ -537,6 +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);
540541
ZEND_API zend_result object_and_properties_init(zval *arg, zend_class_entry *ce, HashTable *properties);
541542
ZEND_API void object_properties_init(zend_object *object, zend_class_entry *class_type);
542543
ZEND_API void object_properties_init_ex(zend_object *object, HashTable *properties);

0 commit comments

Comments
 (0)