@@ -540,15 +540,12 @@ PHP_METHOD(PDO, connect)
540
540
}
541
541
/* }}} */
542
542
543
- static zval * pdo_stmt_instantiate (pdo_dbh_t * dbh , zval * object , zend_class_entry * dbstmt_ce , zval * ctor_args ) /* {{{ */
543
+ static zval * pdo_stmt_instantiate (pdo_dbh_t * dbh , zval * object , zend_class_entry * dbstmt_ce , const HashTable * ctor_args ) /* {{{ */
544
544
{
545
- if (! Z_ISUNDEF_P ( ctor_args ) ) {
545
+ if (ctor_args && dbstmt_ce -> constructor == NULL ) {
546
546
/* This implies an error within PDO if this does not hold */
547
- ZEND_ASSERT (Z_TYPE_P (ctor_args ) == IS_ARRAY );
548
- if (!dbstmt_ce -> constructor ) {
549
- zend_throw_error (NULL , "User-supplied statement does not accept constructor arguments" );
550
- return NULL ;
551
- }
547
+ zend_throw_error (NULL , "User-supplied statement does not accept constructor arguments" );
548
+ return NULL ;
552
549
}
553
550
554
551
if (UNEXPECTED (object_init_ex (object , dbstmt_ce ) != SUCCESS )) {
@@ -581,10 +578,11 @@ PHP_METHOD(PDO, prepare)
581
578
{
582
579
pdo_stmt_t * stmt ;
583
580
zend_string * statement ;
584
- zval * options = NULL , * value , * item , ctor_args ;
581
+ zval * options = NULL , * value , * item ;
585
582
zend_class_entry * dbstmt_ce , * pce ;
586
583
pdo_dbh_object_t * dbh_obj = Z_PDO_OBJECT_P (ZEND_THIS );
587
584
pdo_dbh_t * dbh = dbh_obj -> inner ;
585
+ HashTable * ctor_args = NULL ;
588
586
589
587
ZEND_PARSE_PARAMETERS_START (1 , 2 )
590
588
Z_PARAM_STR (statement )
@@ -631,16 +629,14 @@ PHP_METHOD(PDO, prepare)
631
629
zend_zval_value_name (value ));
632
630
RETURN_THROWS ();
633
631
}
634
- ZVAL_COPY_VALUE (& ctor_args , item );
635
- } else {
636
- ZVAL_UNDEF (& ctor_args );
632
+ ctor_args = Z_ARRVAL_P (item );
637
633
}
638
634
} else {
639
635
dbstmt_ce = dbh -> def_stmt_ce ;
640
- ZVAL_COPY_VALUE ( & ctor_args , & dbh -> def_stmt_ctor_args ) ;
636
+ ctor_args = dbh -> def_stmt_ctor_args ;
641
637
}
642
638
643
- if (!pdo_stmt_instantiate (dbh , return_value , dbstmt_ce , & ctor_args )) {
639
+ if (!pdo_stmt_instantiate (dbh , return_value , dbstmt_ce , ctor_args )) {
644
640
RETURN_THROWS ();
645
641
}
646
642
stmt = Z_PDO_STMT_P (return_value );
@@ -655,11 +651,7 @@ PHP_METHOD(PDO, prepare)
655
651
ZVAL_UNDEF (& stmt -> lazy_object_ref );
656
652
657
653
if (dbh -> methods -> preparer (dbh , statement , stmt , options )) {
658
- if (Z_TYPE (ctor_args ) == IS_ARRAY ) {
659
- pdo_stmt_construct (stmt , return_value , dbstmt_ce , Z_ARRVAL (ctor_args ));
660
- } else {
661
- pdo_stmt_construct (stmt , return_value , dbstmt_ce , /* ctor_args */ NULL );
662
- }
654
+ pdo_stmt_construct (stmt , return_value , dbstmt_ce , ctor_args );
663
655
return ;
664
656
}
665
657
@@ -923,17 +915,19 @@ static bool pdo_dbh_attribute_set(pdo_dbh_t *dbh, zend_long attr, zval *value) /
923
915
return false;
924
916
}
925
917
dbh -> def_stmt_ce = pce ;
926
- if (! Z_ISUNDEF ( dbh -> def_stmt_ctor_args ) ) {
927
- zval_ptr_dtor ( & dbh -> def_stmt_ctor_args );
928
- ZVAL_UNDEF ( & dbh -> def_stmt_ctor_args ) ;
918
+ if (dbh -> def_stmt_ctor_args != NULL ) {
919
+ zend_array_release ( dbh -> def_stmt_ctor_args );
920
+ dbh -> def_stmt_ctor_args = NULL ;
929
921
}
930
922
if ((item = zend_hash_index_find (Z_ARRVAL_P (value ), 1 )) != NULL ) {
931
923
if (Z_TYPE_P (item ) != IS_ARRAY ) {
932
924
zend_type_error ("PDO::ATTR_STATEMENT_CLASS constructor_args must be of type ?array, %s given" ,
933
925
zend_zval_value_name (value ));
934
926
return false;
935
927
}
936
- ZVAL_COPY (& dbh -> def_stmt_ctor_args , item );
928
+ dbh -> def_stmt_ctor_args = Z_ARRVAL_P (item );
929
+ /* Increase refcount */
930
+ GC_TRY_ADDREF (dbh -> def_stmt_ctor_args );
937
931
}
938
932
return true;
939
933
}
@@ -1012,9 +1006,10 @@ PHP_METHOD(PDO, getAttribute)
1012
1006
case PDO_ATTR_STATEMENT_CLASS :
1013
1007
array_init (return_value );
1014
1008
add_next_index_str (return_value , zend_string_copy (dbh -> def_stmt_ce -> name ));
1015
- if (!Z_ISUNDEF (dbh -> def_stmt_ctor_args )) {
1016
- Z_TRY_ADDREF (dbh -> def_stmt_ctor_args );
1017
- add_next_index_zval (return_value , & dbh -> def_stmt_ctor_args );
1009
+ if (dbh -> def_stmt_ctor_args != NULL ) {
1010
+ /* Increase refcount */
1011
+ GC_TRY_ADDREF (dbh -> def_stmt_ctor_args );
1012
+ add_next_index_array (return_value , dbh -> def_stmt_ctor_args );
1018
1013
}
1019
1014
return ;
1020
1015
@@ -1204,7 +1199,7 @@ PHP_METHOD(PDO, query)
1204
1199
1205
1200
PDO_DBH_CLEAR_ERR ();
1206
1201
1207
- if (!pdo_stmt_instantiate (dbh , return_value , dbh -> def_stmt_ce , & dbh -> def_stmt_ctor_args )) {
1202
+ if (!pdo_stmt_instantiate (dbh , return_value , dbh -> def_stmt_ce , dbh -> def_stmt_ctor_args )) {
1208
1203
RETURN_THROWS ();
1209
1204
}
1210
1205
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
}
@@ -1495,8 +1489,9 @@ static void dbh_free(pdo_dbh_t *dbh, bool free_persistent)
1495
1489
pefree ((char * )dbh -> persistent_id , dbh -> is_persistent );
1496
1490
}
1497
1491
1498
- if (!Z_ISUNDEF (dbh -> def_stmt_ctor_args )) {
1499
- zval_ptr_dtor (& dbh -> def_stmt_ctor_args );
1492
+ if (dbh -> def_stmt_ctor_args != NULL ) {
1493
+ zend_array_release (dbh -> def_stmt_ctor_args );
1494
+ dbh -> def_stmt_ctor_args = NULL ;
1500
1495
}
1501
1496
1502
1497
for (i = 0 ; i < PDO_DBH_DRIVER_METHOD_KIND__MAX ; i ++ ) {
@@ -1541,6 +1536,7 @@ zend_object *pdo_dbh_new(zend_class_entry *ce)
1541
1536
zend_std_get_properties_ex (& dbh -> std );
1542
1537
dbh -> inner = ecalloc (1 , sizeof (pdo_dbh_t ));
1543
1538
dbh -> inner -> def_stmt_ce = pdo_dbstmt_ce ;
1539
+ dbh -> inner -> def_stmt_ctor_args = NULL ;
1544
1540
1545
1541
return & dbh -> std ;
1546
1542
}
0 commit comments