Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ext/pgsql/pgsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -1876,6 +1876,11 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, zend_long result_

ZVAL_COPY_VALUE(&dataset, return_value);
object_init_ex(return_value, ce);
if (UNEXPECTED(EG(exception))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the return value of object_init_ex instead

zval_ptr_dtor(&dataset);
zval_ptr_dtor(return_value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop this line , zval_ptr_dtor of the return value followed by a return statement is always wrong.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, zval_ptr_dtor(&dataset); should also be dropped as dataset is a borrow of the return value.

RETURN_THROWS();
}
if (!ce->default_properties_count && !ce->__set) {
Z_OBJ_P(return_value)->properties = Z_ARR(dataset);
} else {
Expand Down
58 changes: 58 additions & 0 deletions ext/pgsql/tests/pg_fetch_object_with_abstract_class.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
--TEST--
pg_fetch_object() with abstract class name
--EXTENSIONS--
pgsql
--SKIPIF--
<?php
include("skipif.inc");
?>
--FILE--
<?php

interface I {}

abstract class C {}

enum E {
case A;
}

include "config.inc";
$table_name = "pg_fetch_object_abstract_class";
$db = pg_connect($conn_str);
pg_query($db, "CREATE TABLE {$table_name} (a integer, b text)");
pg_query($db, "INSERT INTO {$table_name} VALUES(0, 'ABC')");

$sql = "SELECT * FROM $table_name WHERE a = 0";

try {
$result = pg_query($db, $sql);
var_dump(pg_fetch_object($result, NULL, 'I'));
} catch(Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

try {
$result = pg_query($db, $sql);
var_dump(pg_fetch_object($result, NULL, 'C'));
} catch(Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

try {
$result = pg_query($db, $sql);
var_dump(pg_fetch_object($result, NULL, 'E'));
} catch(Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe try without this last PHP_EOL wdyt ?

}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: would it be possible to add the closing tag ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might also be the reason windows is confused

--CLEAN--
<?php
include('config.inc');
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS pg_fetch_object_abstract_class cascade");
?>
--EXPECT--
Error: Cannot instantiate interface I
Error: Cannot instantiate abstract class C
Error: Cannot instantiate enum E
Loading