@@ -836,14 +836,14 @@ static bool do_fetch(pdo_stmt_t *stmt, zval *return_value, enum pdo_fetch_type h
836
836
837
837
case PDO_FETCH_INTO :
838
838
/* TODO: Make this an assertion and ensure this is true higher up? */
839
- if (Z_ISUNDEF ( stmt -> fetch .into ) ) {
839
+ if (stmt -> fetch .into == NULL ) {
840
840
/* TODO ArgumentCountError? */
841
841
pdo_raise_impl_error (stmt -> dbh , stmt , "HY000" , "No fetch-into object specified." );
842
842
return 0 ;
843
843
break ;
844
844
}
845
845
846
- ZVAL_COPY (return_value , & stmt -> fetch .into );
846
+ ZVAL_OBJ_COPY (return_value , stmt -> fetch .into );
847
847
848
848
if (Z_OBJ_P (return_value )-> ce == ZEND_STANDARD_CLASS_DEF_PTR ) {
849
849
how = PDO_FETCH_OBJ ;
@@ -1655,9 +1655,9 @@ bool pdo_stmt_setup_fetch_mode(pdo_stmt_t *stmt, zend_long mode, uint32_t mode_a
1655
1655
1656
1656
switch (stmt -> default_fetch_type ) {
1657
1657
case PDO_FETCH_INTO :
1658
- if (! Z_ISUNDEF ( stmt -> fetch .into ) ) {
1659
- zval_ptr_dtor ( & stmt -> fetch .into );
1660
- ZVAL_UNDEF ( & stmt -> fetch .into ) ;
1658
+ if (stmt -> fetch .into ) {
1659
+ OBJ_RELEASE ( stmt -> fetch .into );
1660
+ stmt -> fetch .into = NULL ;
1661
1661
}
1662
1662
break ;
1663
1663
default :
@@ -1786,7 +1786,8 @@ bool pdo_stmt_setup_fetch_mode(pdo_stmt_t *stmt, zend_long mode, uint32_t mode_a
1786
1786
return false;
1787
1787
}
1788
1788
1789
- ZVAL_COPY (& stmt -> fetch .into , & args [0 ]);
1789
+ GC_ADDREF (Z_OBJ (args [0 ]));
1790
+ stmt -> fetch .into = Z_OBJ (args [0 ]);
1790
1791
break ;
1791
1792
default :
1792
1793
zend_argument_value_error (mode_arg_num , "must be one of the PDO::FETCH_* constants" );
@@ -2027,10 +2028,15 @@ static zend_function *dbstmt_method_get(zend_object **object_pp, zend_string *me
2027
2028
static HashTable * dbstmt_get_gc (zend_object * object , zval * * gc_data , int * gc_count )
2028
2029
{
2029
2030
pdo_stmt_t * stmt = php_pdo_stmt_fetch_object (object );
2031
+ enum pdo_fetch_type default_fetch_mode = stmt -> default_fetch_type & ~PDO_FETCH_FLAGS ;
2030
2032
2031
2033
zend_get_gc_buffer * gc_buffer = zend_get_gc_buffer_create ();
2032
2034
zend_get_gc_buffer_add_zval (gc_buffer , & stmt -> database_object_handle );
2033
- zend_get_gc_buffer_add_zval (gc_buffer , & stmt -> fetch .into );
2035
+ if (default_fetch_mode == PDO_FETCH_INTO ) {
2036
+ zend_get_gc_buffer_add_obj (gc_buffer , stmt -> fetch .into );
2037
+ } else if (default_fetch_mode == PDO_FETCH_CLASS ) {
2038
+ zend_get_gc_buffer_add_zval (gc_buffer , & stmt -> fetch .cls .ctor_args );
2039
+ }
2034
2040
zend_get_gc_buffer_use (gc_buffer , gc_data , gc_count );
2035
2041
2036
2042
/**
@@ -2077,9 +2083,9 @@ PDO_API void php_pdo_free_statement(pdo_stmt_t *stmt)
2077
2083
2078
2084
pdo_stmt_reset_columns (stmt );
2079
2085
2080
- if (! Z_ISUNDEF ( stmt -> fetch .into ) && stmt -> default_fetch_type == PDO_FETCH_INTO ) {
2081
- zval_ptr_dtor ( & stmt -> fetch .into );
2082
- ZVAL_UNDEF ( & stmt -> fetch .into ) ;
2086
+ if (stmt -> fetch .into && stmt -> default_fetch_type == PDO_FETCH_INTO ) {
2087
+ OBJ_RELEASE ( stmt -> fetch .into );
2088
+ stmt -> fetch .into = NULL ;
2083
2089
}
2084
2090
2085
2091
do_fetch_opt_finish (stmt , 1 );
@@ -2168,7 +2174,6 @@ static void pdo_stmt_iter_move_forwards(zend_object_iterator *iter)
2168
2174
2169
2175
if (!do_fetch (stmt , & I -> fetch_ahead , PDO_FETCH_USE_DEFAULT ,
2170
2176
PDO_FETCH_ORI_NEXT , /* offset */ 0 , NULL )) {
2171
-
2172
2177
PDO_HANDLE_STMT_ERR ();
2173
2178
I -> key = (zend_ulong )- 1 ;
2174
2179
ZVAL_UNDEF (& I -> fetch_ahead );
0 commit comments