@@ -425,11 +425,8 @@ PHP_METHOD(PDO, __construct)
425
425
static zval * pdo_stmt_instantiate (pdo_dbh_t * dbh , zval * object , zend_class_entry * dbstmt_ce , zval * ctor_args ) /* {{{ */
426
426
{
427
427
if (!Z_ISUNDEF_P (ctor_args )) {
428
- if (Z_TYPE_P (ctor_args ) != IS_ARRAY ) {
429
- /* TODO Always TypeError */
430
- pdo_raise_impl_error (dbh , NULL , "HY000" , "constructor arguments must be passed as an array" );
431
- return NULL ;
432
- }
428
+ /* This implies an error within PDO if this does not hold */
429
+ ZEND_ASSERT (Z_TYPE_P (ctor_args ) == IS_ARRAY );
433
430
if (!dbstmt_ce -> constructor ) {
434
431
/* TODO Error? */
435
432
pdo_raise_impl_error (dbh , NULL , "HY000" , "user-supplied statement does not accept constructor arguments" );
@@ -489,7 +486,7 @@ PHP_METHOD(PDO, prepare)
489
486
pdo_stmt_t * stmt ;
490
487
char * statement ;
491
488
size_t statement_len ;
492
- zval * options = NULL , * opt , * item , ctor_args ;
489
+ zval * options = NULL , * value , * item , ctor_args ;
493
490
zend_class_entry * dbstmt_ce , * pce ;
494
491
pdo_dbh_object_t * dbh_obj = Z_PDO_OBJECT_P (ZEND_THIS );
495
492
pdo_dbh_t * dbh = dbh_obj -> inner ;
@@ -503,43 +500,38 @@ PHP_METHOD(PDO, prepare)
503
500
PDO_DBH_CLEAR_ERR ();
504
501
PDO_CONSTRUCT_CHECK ;
505
502
506
- if (ZEND_NUM_ARGS () > 1 && (opt = zend_hash_index_find (Z_ARRVAL_P (options ), PDO_ATTR_STATEMENT_CLASS )) != NULL ) {
507
- if (Z_TYPE_P (opt ) != IS_ARRAY || (item = zend_hash_index_find (Z_ARRVAL_P (opt ), 0 )) == NULL
508
- || Z_TYPE_P (item ) != IS_STRING
509
- || (pce = zend_lookup_class (Z_STR_P (item ))) == NULL
510
- ) {
511
- /* TODO Always TypeError */
512
- pdo_raise_impl_error (dbh , NULL , "HY000" ,
513
- "PDO::ATTR_STATEMENT_CLASS requires format array(classname, array(ctor_args)); "
514
- "the classname must be a string specifying an existing class"
515
- );
516
- PDO_HANDLE_DBH_ERR ();
517
- RETURN_FALSE ;
503
+ if (options && (value = zend_hash_index_find (Z_ARRVAL_P (options ), PDO_ATTR_STATEMENT_CLASS )) != NULL ) {
504
+ if (Z_TYPE_P (value ) != IS_ARRAY ) {
505
+ zend_type_error ("PDO::ATTR_STATEMENT_CLASS's value must be of type array, %s given" ,
506
+ zend_zval_type_name (value ));
507
+ RETURN_THROWS ();
508
+ }
509
+ if ((item = zend_hash_index_find (Z_ARRVAL_P (value ), 0 )) == NULL ) {
510
+ zend_value_error ("PDO::ATTR_STATEMENT_CLASS's value must be an array with the following "
511
+ "format array(classname, array(ctor_args))" );
512
+ RETURN_THROWS ();
513
+ }
514
+ if (Z_TYPE_P (item ) != IS_STRING || (pce = zend_lookup_class (Z_STR_P (item ))) == NULL ) {
515
+ zend_type_error ("PDO::ATTR_STATEMENT_CLASS's class must be a valid class" );
516
+ RETURN_THROWS ();
518
517
}
519
518
dbstmt_ce = pce ;
520
519
if (!instanceof_function (dbstmt_ce , pdo_dbstmt_ce )) {
521
- /* TODO Always TypeError */
522
- pdo_raise_impl_error (dbh , NULL , "HY000" ,
523
- "user-supplied statement class must be derived from PDOStatement" );
524
- PDO_HANDLE_DBH_ERR ();
525
- RETURN_FALSE ;
520
+ zend_type_error ("PDO::ATTR_STATEMENT_CLASS's class must be derived from PDOStatement" );
521
+ RETURN_THROWS ();
526
522
}
527
523
if (dbstmt_ce -> constructor && !(dbstmt_ce -> constructor -> common .fn_flags & (ZEND_ACC_PRIVATE |ZEND_ACC_PROTECTED ))) {
528
- /* TODO Always TError */
524
+ /* TODO Always Error? */
529
525
pdo_raise_impl_error (dbh , NULL , "HY000" ,
530
526
"user-supplied statement class cannot have a public constructor" );
531
527
PDO_HANDLE_DBH_ERR ();
532
528
RETURN_FALSE ;
533
529
}
534
- if ((item = zend_hash_index_find (Z_ARRVAL_P (opt ), 1 )) != NULL ) {
530
+ if ((item = zend_hash_index_find (Z_ARRVAL_P (value ), 1 )) != NULL ) {
535
531
if (Z_TYPE_P (item ) != IS_ARRAY ) {
536
- /* TODO Always TypeError */
537
- pdo_raise_impl_error (dbh , NULL , "HY000" ,
538
- "PDO::ATTR_STATEMENT_CLASS requires format array(classname, ctor_args); "
539
- "ctor_args must be an array"
540
- );
541
- PDO_HANDLE_DBH_ERR ();
542
- RETURN_FALSE ;
532
+ zend_type_error ("PDO::ATTR_STATEMENT_CLASS's ctor_args must be ?array, %s given" ,
533
+ zend_zval_type_name (value ));
534
+ RETURN_THROWS ();
543
535
}
544
536
ZVAL_COPY_VALUE (& ctor_args , item );
545
537
} else {
0 commit comments