Skip to content

Commit 03b6925

Browse files
committed
ext/pgsql: move object initialization before fetching row in pg_fetch_object
1 parent bd78496 commit 03b6925

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

ext/pgsql/pgsql.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2129,6 +2129,11 @@ PHP_FUNCTION(pg_fetch_object)
21292129
ce = zend_standard_class_def;
21302130
}
21312131

2132+
zend_result obj_initialized = object_init_ex(return_value, ce);
2133+
if (UNEXPECTED(obj_initialized == FAILURE)) {
2134+
RETURN_THROWS();
2135+
}
2136+
21322137
if (!ce->constructor && ctor_params && zend_hash_num_elements(ctor_params) > 0) {
21332138
zend_argument_value_error(3,
21342139
"must be empty when the specified class (%s) does not have a constructor",
@@ -2140,15 +2145,9 @@ PHP_FUNCTION(pg_fetch_object)
21402145
zval dataset;
21412146
if (UNEXPECTED(!php_pgsql_fetch_hash(&dataset, result, row, row_is_null, PGSQL_ASSOC))) {
21422147
/* Either an exception is thrown, or we return false */
2143-
RETURN_FALSE;
2144-
}
2145-
2146-
// TODO: Check CE is an instantiable class earlier?
2147-
zend_result obj_initialized = object_init_ex(return_value, ce);
2148-
if (UNEXPECTED(obj_initialized == FAILURE)) {
2149-
zval_ptr_dtor(&dataset);
21502148
RETURN_THROWS();
21512149
}
2150+
21522151
if (!ce->default_properties_count && !ce->__set) {
21532152
Z_OBJ_P(return_value)->properties = Z_ARR(dataset);
21542153
} else {

0 commit comments

Comments
 (0)