@@ -542,15 +542,12 @@ PHP_METHOD(PDO, connect)
542
542
}
543
543
/* }}} */
544
544
545
- static zval * pdo_stmt_instantiate (pdo_dbh_t * dbh , zval * object , zend_class_entry * dbstmt_ce , zval * ctor_args ) /* {{{ */
545
+ static zval * pdo_stmt_instantiate (pdo_dbh_t * dbh , zval * object , zend_class_entry * dbstmt_ce , const HashTable * ctor_args ) /* {{{ */
546
546
{
547
- if (! Z_ISUNDEF_P ( ctor_args ) ) {
547
+ if (ctor_args && dbstmt_ce -> constructor == NULL ) {
548
548
/* This implies an error within PDO if this does not hold */
549
- ZEND_ASSERT (Z_TYPE_P (ctor_args ) == IS_ARRAY );
550
- if (!dbstmt_ce -> constructor ) {
551
- zend_throw_error (NULL , "User-supplied statement does not accept constructor arguments" );
552
- return NULL ;
553
- }
549
+ zend_throw_error (NULL , "User-supplied statement does not accept constructor arguments" );
550
+ return NULL ;
554
551
}
555
552
556
553
if (UNEXPECTED (object_init_ex (object , dbstmt_ce ) != SUCCESS )) {
@@ -583,10 +580,11 @@ PHP_METHOD(PDO, prepare)
583
580
{
584
581
pdo_stmt_t * stmt ;
585
582
zend_string * statement ;
586
- zval * options = NULL , * value , * item , ctor_args ;
583
+ zval * options = NULL , * value , * item ;
587
584
zend_class_entry * dbstmt_ce , * pce ;
588
585
pdo_dbh_object_t * dbh_obj = Z_PDO_OBJECT_P (ZEND_THIS );
589
586
pdo_dbh_t * dbh = dbh_obj -> inner ;
587
+ HashTable * ctor_args = NULL ;
590
588
591
589
ZEND_PARSE_PARAMETERS_START (1 , 2 )
592
590
Z_PARAM_STR (statement )
@@ -633,16 +631,14 @@ PHP_METHOD(PDO, prepare)
633
631
zend_zval_value_name (value ));
634
632
RETURN_THROWS ();
635
633
}
636
- ZVAL_COPY_VALUE (& ctor_args , item );
637
- } else {
638
- ZVAL_UNDEF (& ctor_args );
634
+ ctor_args = Z_ARRVAL_P (item );
639
635
}
640
636
} else {
641
637
dbstmt_ce = dbh -> def_stmt_ce ;
642
- ZVAL_COPY_VALUE ( & ctor_args , & dbh -> def_stmt_ctor_args ) ;
638
+ ctor_args = dbh -> def_stmt_ctor_args ;
643
639
}
644
640
645
- if (!pdo_stmt_instantiate (dbh , return_value , dbstmt_ce , & ctor_args )) {
641
+ if (!pdo_stmt_instantiate (dbh , return_value , dbstmt_ce , ctor_args )) {
646
642
RETURN_THROWS ();
647
643
}
648
644
stmt = Z_PDO_STMT_P (return_value );
@@ -656,11 +652,7 @@ PHP_METHOD(PDO, prepare)
656
652
stmt -> database_object_handle = & dbh_obj -> std ;
657
653
658
654
if (dbh -> methods -> preparer (dbh , statement , stmt , options )) {
659
- if (Z_TYPE (ctor_args ) == IS_ARRAY ) {
660
- pdo_stmt_construct (stmt , return_value , dbstmt_ce , Z_ARRVAL (ctor_args ));
661
- } else {
662
- pdo_stmt_construct (stmt , return_value , dbstmt_ce , /* ctor_args */ NULL );
663
- }
655
+ pdo_stmt_construct (stmt , return_value , dbstmt_ce , ctor_args );
664
656
return ;
665
657
}
666
658
@@ -924,17 +916,19 @@ static bool pdo_dbh_attribute_set(pdo_dbh_t *dbh, zend_long attr, zval *value, u
924
916
return false;
925
917
}
926
918
dbh -> def_stmt_ce = pce ;
927
- if (! Z_ISUNDEF ( dbh -> def_stmt_ctor_args ) ) {
928
- zval_ptr_dtor ( & dbh -> def_stmt_ctor_args );
929
- ZVAL_UNDEF ( & dbh -> def_stmt_ctor_args ) ;
919
+ if (dbh -> def_stmt_ctor_args != NULL ) {
920
+ zend_array_release ( dbh -> def_stmt_ctor_args );
921
+ dbh -> def_stmt_ctor_args = NULL ;
930
922
}
931
923
if ((item = zend_hash_index_find (Z_ARRVAL_P (value ), 1 )) != NULL ) {
932
924
if (Z_TYPE_P (item ) != IS_ARRAY ) {
933
925
zend_argument_type_error (value_arg_num , "PDO::ATTR_STATEMENT_CLASS constructor_args must be of type ?array, %s given" ,
934
926
zend_zval_value_name (value ));
935
927
return false;
936
928
}
937
- ZVAL_COPY (& dbh -> def_stmt_ctor_args , item );
929
+ dbh -> def_stmt_ctor_args = Z_ARRVAL_P (item );
930
+ /* Increase refcount */
931
+ GC_TRY_ADDREF (dbh -> def_stmt_ctor_args );
938
932
}
939
933
return true;
940
934
}
@@ -1013,9 +1007,10 @@ PHP_METHOD(PDO, getAttribute)
1013
1007
case PDO_ATTR_STATEMENT_CLASS :
1014
1008
array_init (return_value );
1015
1009
add_next_index_str (return_value , zend_string_copy (dbh -> def_stmt_ce -> name ));
1016
- if (!Z_ISUNDEF (dbh -> def_stmt_ctor_args )) {
1017
- Z_TRY_ADDREF (dbh -> def_stmt_ctor_args );
1018
- add_next_index_zval (return_value , & dbh -> def_stmt_ctor_args );
1010
+ if (dbh -> def_stmt_ctor_args != NULL ) {
1011
+ /* Increase refcount */
1012
+ GC_TRY_ADDREF (dbh -> def_stmt_ctor_args );
1013
+ add_next_index_array (return_value , dbh -> def_stmt_ctor_args );
1019
1014
}
1020
1015
return ;
1021
1016
@@ -1205,7 +1200,7 @@ PHP_METHOD(PDO, query)
1205
1200
1206
1201
PDO_DBH_CLEAR_ERR ();
1207
1202
1208
- if (!pdo_stmt_instantiate (dbh , return_value , dbh -> def_stmt_ce , & dbh -> def_stmt_ctor_args )) {
1203
+ if (!pdo_stmt_instantiate (dbh , return_value , dbh -> def_stmt_ce , dbh -> def_stmt_ctor_args )) {
1209
1204
RETURN_THROWS ();
1210
1205
}
1211
1206
stmt = Z_PDO_STMT_P (return_value );
@@ -1233,11 +1228,7 @@ PHP_METHOD(PDO, query)
1233
1228
stmt -> executed = 1 ;
1234
1229
}
1235
1230
if (ret ) {
1236
- if (Z_TYPE (dbh -> def_stmt_ctor_args ) == IS_ARRAY ) {
1237
- pdo_stmt_construct (stmt , return_value , dbh -> def_stmt_ce , Z_ARRVAL (dbh -> def_stmt_ctor_args ));
1238
- } else {
1239
- pdo_stmt_construct (stmt , return_value , dbh -> def_stmt_ce , /* ctor_args */ NULL );
1240
- }
1231
+ pdo_stmt_construct (stmt , return_value , dbh -> def_stmt_ce , dbh -> def_stmt_ctor_args );
1241
1232
return ;
1242
1233
}
1243
1234
}
@@ -1432,7 +1423,10 @@ static HashTable *dbh_get_gc(zend_object *object, zval **gc_data, int *gc_count)
1432
1423
{
1433
1424
pdo_dbh_t * dbh = php_pdo_dbh_fetch_inner (object );
1434
1425
zend_get_gc_buffer * gc_buffer = zend_get_gc_buffer_create ();
1435
- zend_get_gc_buffer_add_zval (gc_buffer , & dbh -> def_stmt_ctor_args );
1426
+ if (dbh -> def_stmt_ctor_args != NULL ) {
1427
+ zend_get_gc_buffer_add_ht (gc_buffer , dbh -> def_stmt_ctor_args );
1428
+ dbh -> def_stmt_ctor_args = NULL ;
1429
+ }
1436
1430
if (dbh -> methods && dbh -> methods -> get_gc ) {
1437
1431
dbh -> methods -> get_gc (dbh , gc_buffer );
1438
1432
}
@@ -1496,8 +1490,9 @@ static void dbh_free(pdo_dbh_t *dbh, bool free_persistent)
1496
1490
pefree ((char * )dbh -> persistent_id , dbh -> is_persistent );
1497
1491
}
1498
1492
1499
- if (!Z_ISUNDEF (dbh -> def_stmt_ctor_args )) {
1500
- zval_ptr_dtor (& dbh -> def_stmt_ctor_args );
1493
+ if (dbh -> def_stmt_ctor_args != NULL ) {
1494
+ zend_array_release (dbh -> def_stmt_ctor_args );
1495
+ dbh -> def_stmt_ctor_args = NULL ;
1501
1496
}
1502
1497
1503
1498
for (i = 0 ; i < PDO_DBH_DRIVER_METHOD_KIND__MAX ; i ++ ) {
@@ -1542,6 +1537,7 @@ zend_object *pdo_dbh_new(zend_class_entry *ce)
1542
1537
zend_std_get_properties_ex (& dbh -> std );
1543
1538
dbh -> inner = ecalloc (1 , sizeof (pdo_dbh_t ));
1544
1539
dbh -> inner -> def_stmt_ce = pdo_dbstmt_ce ;
1540
+ dbh -> inner -> def_stmt_ctor_args = NULL ;
1545
1541
1546
1542
return & dbh -> std ;
1547
1543
}
0 commit comments