Skip to content

Commit 243b173

Browse files
committed
ext/pdo: fetch with PDO::FETCH insures the statement is actually a class
beforehand.
1 parent fb5e77b commit 243b173

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

ext/pdo/pdo_stmt.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -833,12 +833,7 @@ static bool do_fetch(pdo_stmt_t *stmt, zval *return_value, enum pdo_fetch_type h
833833
zval_ptr_dtor_str(&val);
834834
}
835835
ce = stmt->fetch.cls.ce;
836-
/* TODO: Make this an assertion and ensure this is true higher up? */
837-
if (!ce) {
838-
/* TODO Error? */
839-
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "No fetch class specified");
840-
return 0;
841-
}
836+
ZEND_ASSERT(ce && "No fetch class specified");
842837
if ((flags & PDO_FETCH_SERIALIZE) == 0) {
843838
if (UNEXPECTED(object_init_ex(return_value, ce) != SUCCESS)) {
844839
return 0;
@@ -1140,6 +1135,10 @@ static bool pdo_stmt_verify_mode(pdo_stmt_t *stmt, zend_long mode, uint32_t mode
11401135
ZEND_FALLTHROUGH;
11411136

11421137
case PDO_FETCH_CLASS:
1138+
if (!stmt->fetch.cls.ce) {
1139+
zend_argument_value_error(mode_arg_num, "must use PDO::FETCH_CLASS with a class instance");
1140+
return 0;
1141+
}
11431142
if (flags & PDO_FETCH_SERIALIZE) {
11441143
php_error_docref(NULL, E_DEPRECATED, "The PDO::FETCH_SERIALIZE mode is deprecated");
11451144
}

0 commit comments

Comments
 (0)