Skip to content

Commit

Permalink
Drop php_pdo_get_exception_base() function
Browse files Browse the repository at this point in the history
This API is more confusing than helpful.
  • Loading branch information
nikic committed Aug 11, 2020
1 parent 33028bf commit 898bb97
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 17 deletions.
11 changes: 1 addition & 10 deletions ext/pdo/pdo.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,6 @@ PDO_API char *php_pdo_str_tolower_dup(const char *src, int len) /* {{{ */
}
/* }}} */

PDO_API zend_class_entry *php_pdo_get_exception_base(int root) /* {{{ */
{
if (!root) {
return spl_ce_RuntimeException;
}
return zend_ce_exception;
}
/* }}} */

/* {{{ Return array of available PDO drivers */
PHP_FUNCTION(pdo_drivers)
{
Expand Down Expand Up @@ -315,7 +306,7 @@ PHP_MINIT_FUNCTION(pdo)

INIT_CLASS_ENTRY(ce, "PDOException", NULL);

pdo_exception_ce = zend_register_internal_class_ex(&ce, php_pdo_get_exception_base(0));
pdo_exception_ce = zend_register_internal_class_ex(&ce, spl_ce_RuntimeException);

zend_declare_property_null(pdo_exception_ce, "errorInfo", sizeof("errorInfo")-1, ZEND_ACC_PUBLIC);

Expand Down
12 changes: 6 additions & 6 deletions ext/pdo/pdo_dbh.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ void pdo_raise_impl_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *sqlstate
php_error_docref(NULL, E_WARNING, "%s", message);
} else {
zval ex, info;
zend_class_entry *def_ex = php_pdo_get_exception_base(1), *pdo_ex = php_pdo_get_exception();
zend_class_entry *pdo_ex = php_pdo_get_exception();

object_init_ex(&ex, pdo_ex);

zend_update_property_string(def_ex, Z_OBJ(ex), "message", sizeof("message")-1, message);
zend_update_property_string(def_ex, Z_OBJ(ex), "code", sizeof("code")-1, *pdo_err);
zend_update_property_string(zend_ce_exception, Z_OBJ(ex), "message", sizeof("message")-1, message);
zend_update_property_string(zend_ce_exception, Z_OBJ(ex), "code", sizeof("code")-1, *pdo_err);

array_init(&info);

Expand Down Expand Up @@ -175,12 +175,12 @@ PDO_API void pdo_handle_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt) /* {{{ */
php_error_docref(NULL, E_WARNING, "%s", ZSTR_VAL(message));
} else if (EG(exception) == NULL) {
zval ex;
zend_class_entry *def_ex = php_pdo_get_exception_base(1), *pdo_ex = php_pdo_get_exception();
zend_class_entry *pdo_ex = php_pdo_get_exception();

object_init_ex(&ex, pdo_ex);

zend_update_property_str(def_ex, Z_OBJ(ex), "message", sizeof("message") - 1, message);
zend_update_property_string(def_ex, Z_OBJ(ex), "code", sizeof("code") - 1, *pdo_err);
zend_update_property_str(zend_ce_exception, Z_OBJ(ex), "message", sizeof("message") - 1, message);
zend_update_property_string(zend_ce_exception, Z_OBJ(ex), "code", sizeof("code") - 1, *pdo_err);

if (!Z_ISUNDEF(info)) {
zend_update_property(pdo_ex, Z_OBJ(ex), "errorInfo", sizeof("errorInfo") - 1, &info);
Expand Down
1 change: 0 additions & 1 deletion ext/pdo/php_pdo_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

extern HashTable pdo_driver_hash;
extern zend_class_entry *pdo_exception_ce;
PDO_API zend_class_entry *php_pdo_get_exception_base(int root);
int php_pdo_list_entry(void);

void pdo_dbh_init(void);
Expand Down

0 comments on commit 898bb97

Please sign in to comment.