Skip to content

Commit

Permalink
Use zpp C in pg_fetch_object
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Aug 13, 2020
1 parent 670036e commit 396b470
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
12 changes: 2 additions & 10 deletions ext/pgsql/pgsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -2480,19 +2480,11 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, zend_long result_
zend_class_entry *ce = NULL;

if (into_object) {
zend_string *class_name = NULL;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|z!Sz", &result, &zrow, &class_name, &ctor_params) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|z!Cz", &result, &zrow, &ce, &ctor_params) == FAILURE) {
RETURN_THROWS();
}
if (!class_name) {
ce = zend_standard_class_def;
} else {
ce = zend_fetch_class(class_name, ZEND_FETCH_CLASS_AUTO);
}
if (!ce) {
php_error_docref(NULL, E_WARNING, "Could not find class '%s'", ZSTR_VAL(class_name));
return;
ce = zend_standard_class_def;
}
result_type = PGSQL_ASSOC;
} else {
Expand Down
7 changes: 7 additions & 0 deletions ext/pgsql/tests/22pg_fetch_object.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ $rows = pg_num_rows($result);

var_dump(pg_fetch_object($result, NULL, 'test_class', array(1, 2)));

try {
var_dump(pg_fetch_object($result, NULL, 'does_not_exist'));
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}

echo "Ok\n";
?>
--EXPECT--
Expand All @@ -34,4 +40,5 @@ object(test_class)#1 (3) {
["bin"]=>
NULL
}
pg_fetch_object(): Argument #3 ($class_name) must be a valid class name, does_not_exist given
Ok

0 comments on commit 396b470

Please sign in to comment.