#define Z_PARAM_CLASS(dest) \
Z_PARAM_CLASS_EX(dest, 0, 0)
+#define Z_PARAM_CLASS_OR_NULL(dest) \
+ Z_PARAM_CLASS_EX(dest, 1, 0)
+
#define Z_PARAM_CLASS_NAME_OR_OBJ_EX(dest, allow_null) \
Z_PARAM_PROLOGUE(0, 0); \
if (UNEXPECTED(!zend_parse_arg_class_name_or_obj(_arg, &dest, allow_null))) { \
zend_long how = PDO_FETCH_CLASS;
zend_long ori = PDO_FETCH_ORI_NEXT;
zend_long off = 0;
- zend_string *class_name = NULL;
+ zend_class_entry *ce = NULL;
zend_class_entry *old_ce;
zval old_ctor_args, *ctor_args = NULL;
- int error = 0, old_arg_count;
+ int old_arg_count;
ZEND_PARSE_PARAMETERS_START(0, 2)
Z_PARAM_OPTIONAL
- Z_PARAM_STR_EX(class_name, 1, 0)
+ Z_PARAM_CLASS_OR_NULL(ce)
Z_PARAM_ARRAY(ctor_args)
ZEND_PARSE_PARAMETERS_END();
ZVAL_UNDEF(&stmt->fetch.cls.ctor_args);
}
}
- if (class_name && !error) {
- stmt->fetch.cls.ce = zend_fetch_class(class_name, ZEND_FETCH_CLASS_AUTO);
-
- if (!stmt->fetch.cls.ce) {
- pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "Could not find user-supplied class");
- error = 1;
- }
- } else if (!error) {
+ if (ce) {
+ stmt->fetch.cls.ce = ce;
+ } else {
stmt->fetch.cls.ce = zend_standard_class_def;
}
- if (!error && !do_fetch(stmt, TRUE, return_value, how, ori, off, 0)) {
- error = 1;
- }
- if (error) {
+ if (!do_fetch(stmt, TRUE, return_value, how, ori, off, 0)) {
PDO_HANDLE_STMT_ERR();
+ RETVAL_FALSE;
}
do_fetch_opt_finish(stmt, 1);
stmt->fetch.cls.ce = old_ce;
ZVAL_COPY_VALUE(&stmt->fetch.cls.ctor_args, &old_ctor_args);
stmt->fetch.cls.fci.param_count = old_arg_count;
- if (error) {
- RETURN_FALSE;
- }
}
/* }}} */
var_dump($rows[$rowno - 1]);
+ try {
+ $stmt->fetchObject('class_does_not_exist');
+ } catch (TypeError $e) {
+ echo $e->getMessage(), "\n";
+ }
} catch (PDOException $e) {
// we should never get here, we use warnings, but never trust a system...
printf("[001] %s, [%s} %s\n",
["null"]=>
NULL
}
+PDOStatement::fetchObject(): Argument #1 ($class_name) must be a valid class name, class_does_not_exist given
done!