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
63 changes: 62 additions & 1 deletion ext/pdo/pdo_dbh.c
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,9 @@ static void cls_method_dtor(zval *el) /* {{{ */ {
if (ZEND_MAP_PTR(func->common.run_time_cache)) {
efree(ZEND_MAP_PTR(func->common.run_time_cache));
}
if (func->common.attributes) {
zend_hash_release(func->common.attributes);
}
efree(func);
}
/* }}} */
Expand All @@ -1330,10 +1333,39 @@ static void cls_method_pdtor(zval *el) /* {{{ */ {
if (ZEND_MAP_PTR(func->common.run_time_cache)) {
pefree(ZEND_MAP_PTR(func->common.run_time_cache), 1);
}
if (func->common.attributes) {
zend_hash_release(func->common.attributes);
}
pefree(func, 1);
}
/* }}} */

/* We cannot add #[Deprecated] attributes in @generate-function-entries stubs,
Copy link
Member

Choose a reason for hiding this comment

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

oh? Why not? Can you expand no this a bit?
If the support from gen_stub is missing I can try to add it

Copy link
Member Author

Choose a reason for hiding this comment

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

I've expanded a bit when replying to @mvorisek above: #19596 (comment)

Possibly we could improve that a little by adding support for attributes to zend_function_entry, expose a function that copies zend_function_entry attributes to a zend_function, and use that in pdo_dbh.c.

* and PDO drivers have no way to add them either, so we hard-code deprecation
* info here and add the attribute manually in pdo_hash_methods() */
struct driver_specific_method_deprecation {
const char *old_name;
const char *new_name;
};

/* Methods deprecated in https://wiki.php.net/rfc/deprecations_php_8_5
* "Deprecate driver specific PDO constants and methods" */
static const struct driver_specific_method_deprecation driver_specific_method_deprecations[] = {
{"pgsqlCopyFromArray", "Pdo\\Pgsql::copyFromArray"},
{"pgsqlCopyFromFile", "Pdo\\Pgsql::copyFromFile"},
{"pgsqlCopyToArray", "Pdo\\Pgsql::copyToArray"},
{"pgsqlCopyToFile", "Pdo\\Pgsql::copyToFile"},
{"pgsqlGetNotify", "Pdo\\Pgsql::getNotify"},
{"pgsqlGetPid", "Pdo\\Pgsql::getPid"},
{"pgsqlLOBCreate", "Pdo\\Pgsql::lobCreate"},
{"pgsqlLOBOpen", "Pdo\\Pgsql::lobOpen"},
{"pgsqlLOBUnlink", "Pdo\\Pgsql::lobUnlink"},
{"sqliteCreateAggregate", "Pdo\\Sqlite::createAggregate"},
{"sqliteCreateCollation", "Pdo\\Sqlite::createCollation"},
{"sqliteCreateFunction", "Pdo\\Sqlite::createFunction"},
{NULL, NULL},
};

/* {{{ overloaded object handlers for PDO class */
bool pdo_hash_methods(pdo_dbh_object_t *dbh_obj, int kind)
{
Expand Down Expand Up @@ -1371,6 +1403,7 @@ bool pdo_hash_methods(pdo_dbh_object_t *dbh_obj, int kind)
} else {
func.fn_flags = ZEND_ACC_PUBLIC | ZEND_ACC_NEVER_CACHE;
}
func.fn_flags |= ZEND_ACC_DEPRECATED;
func.doc_comment = NULL;
if (funcs->arg_info) {
zend_internal_function_info *info = (zend_internal_function_info*)funcs->arg_info;
Expand Down Expand Up @@ -1399,8 +1432,36 @@ bool pdo_hash_methods(pdo_dbh_object_t *dbh_obj, int kind)
namelen = strlen(funcs->fname);
lc_name = emalloc(namelen+1);
zend_str_tolower_copy(lc_name, funcs->fname, namelen);
zend_hash_str_add_mem(dbh->cls_methods[kind], lc_name, namelen, &func, sizeof(func));
zend_function *func_p = zend_hash_str_add_mem(dbh->cls_methods[kind], lc_name, namelen, &func, sizeof(func));
efree(lc_name);

const char *new_name = NULL;
for (const struct driver_specific_method_deprecation *d = driver_specific_method_deprecations;
d->old_name; d++) {
if (strcmp(d->old_name, funcs->fname) == 0) {
new_name = d->new_name;
break;
}
}
if (new_name) {
uint32_t flags = dbh->is_persistent ? ZEND_ATTRIBUTE_PERSISTENT : 0;
zend_attribute *attr = zend_add_attribute(
&func_p->common.attributes,
ZSTR_KNOWN(ZEND_STR_DEPRECATED_CAPITALIZED),
2, flags, 0, 0);

attr->args[0].name = ZSTR_KNOWN(ZEND_STR_SINCE);
ZVAL_STR(&attr->args[0].value, ZSTR_KNOWN(ZEND_STR_8_DOT_5));

char *message;
size_t len = zend_spprintf(&message, 0, "use %s() instead", new_name);
zend_string *message_str = zend_string_init(message, len, dbh->is_persistent);
efree(message);

attr->args[1].name = ZSTR_KNOWN(ZEND_STR_MESSAGE);
ZVAL_STR(&attr->args[1].value, message_str);
}

funcs++;
}

Expand Down
19 changes: 18 additions & 1 deletion ext/pdo_pgsql/tests/bug68199.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -80,31 +80,48 @@ var_dump($notify[2]);
var_dump($db->pgsqlGetNotify());

?>
--EXPECT--
--EXPECTF--
Deprecated: Method PDO::pgsqlGetPid() is deprecated since 8.5, use Pdo\Pgsql::getPid() instead in %s on line %d
bool(true)

Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
bool(false)

Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
bool(false)

Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
int(3)
string(16) "channel_bug68199"
bool(true)
string(7) "payload"

Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
int(3)
string(16) "channel_bug68199"
bool(true)
string(7) "payload"

Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
int(3)
string(16) "channel_bug68199"
bool(true)
string(7) "payload"

Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
int(3)
string(16) "channel_bug68199"
bool(true)
string(7) "payload"

Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
int(6)
string(16) "channel_bug68199"
bool(true)
string(7) "payload"
string(16) "channel_bug68199"
bool(true)
string(7) "payload"

Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
bool(false)
18 changes: 18 additions & 0 deletions ext/pdo_pgsql/tests/copy_from.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ $db->query('DROP TABLE IF EXISTS test_copy_from CASCADE');
--EXPECTF--
Preparing test file and array for CopyFrom tests
Testing pgsqlCopyFromArray() with default parameters

Deprecated: Method PDO::pgsqlCopyFromArray() is deprecated since 8.5, use Pdo\Pgsql::copyFromArray() instead in %s on line %d
bool(true)
array(6) {
["a"]=>
Expand Down Expand Up @@ -178,6 +180,8 @@ array(6) {
NULL
}
Testing pgsqlCopyFromArray() with different field separator and not null indicator

Deprecated: Method PDO::pgsqlCopyFromArray() is deprecated since 8.5, use Pdo\Pgsql::copyFromArray() instead in %s on line %d
bool(true)
array(6) {
["a"]=>
Expand Down Expand Up @@ -222,6 +226,8 @@ array(6) {
NULL
}
Testing pgsqlCopyFromArray() with only selected fields

Deprecated: Method PDO::pgsqlCopyFromArray() is deprecated since 8.5, use Pdo\Pgsql::copyFromArray() instead in %s on line %d
bool(true)
array(6) {
["a"]=>
Expand Down Expand Up @@ -266,8 +272,12 @@ array(6) {
NULL
}
Testing pgsqlCopyFromArray() with error

Deprecated: Method PDO::pgsqlCopyFromArray() is deprecated since 8.5, use Pdo\Pgsql::copyFromArray() instead in %s on line %d
Exception: SQLSTATE[42P01]: Undefined table: 7 %s: %stest_error%s
Testing pgsqlCopyFromFile() with default parameters

Deprecated: Method PDO::pgsqlCopyFromFile() is deprecated since 8.5, use Pdo\Pgsql::copyFromFile() instead in %s on line %d
bool(true)
array(6) {
["a"]=>
Expand Down Expand Up @@ -312,6 +322,8 @@ array(6) {
NULL
}
Testing pgsqlCopyFromFile() with different field separator and not null indicator

Deprecated: Method PDO::pgsqlCopyFromFile() is deprecated since 8.5, use Pdo\Pgsql::copyFromFile() instead in %s on line %d
bool(true)
array(6) {
["a"]=>
Expand Down Expand Up @@ -356,6 +368,8 @@ array(6) {
NULL
}
Testing pgsqlCopyFromFile() with only selected fields

Deprecated: Method PDO::pgsqlCopyFromFile() is deprecated since 8.5, use Pdo\Pgsql::copyFromFile() instead in %s on line %d
bool(true)
array(6) {
["a"]=>
Expand Down Expand Up @@ -400,6 +414,10 @@ array(6) {
NULL
}
Testing pgsqlCopyFromFile() with error

Deprecated: Method PDO::pgsqlCopyFromFile() is deprecated since 8.5, use Pdo\Pgsql::copyFromFile() instead in %s on line %d
Exception: SQLSTATE[42P01]: Undefined table: 7 %s: %stest_error%s
Testing pgsqlCopyFromFile() with non existing file

Deprecated: Method PDO::pgsqlCopyFromFile() is deprecated since 8.5, use Pdo\Pgsql::copyFromFile() instead in %s on line %d
Exception: SQLSTATE[HY000]: General error: 7 Unable to open the file
3 changes: 2 additions & 1 deletion ext/pdo_pgsql/tests/copy_from_generator.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
$db = PDOTest::test_factory(__DIR__ . '/common.phpt');
$db->query('DROP TABLE IF EXISTS test_copy_from_generator CASCADE');
?>
--EXPECT--
--EXPECTF--
Deprecated: Method PDO::pgsqlCopyFromArray() is deprecated since 8.5, use Pdo\Pgsql::copyFromArray() instead in %s on line %d
array (
0 => 1,
1 => 1,
Expand Down
5 changes: 4 additions & 1 deletion ext/pdo_pgsql/tests/copy_from_iterator.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
$db = PDOTest::test_factory(__DIR__ . '/common.phpt');
$db->query('DROP TABLE IF EXISTS test_copy_from_traversable CASCADE');
?>
--EXPECT--
--EXPECTF--
Deprecated: Method PDO::pgsqlCopyFromArray() is deprecated since 8.5, use Pdo\Pgsql::copyFromArray() instead in %s on line %d
PDO::pgsqlCopyFromArray(): Argument #2 ($rows) must be of type Traversable|array, stdClass given

Deprecated: Method PDO::pgsqlCopyFromArray() is deprecated since 8.5, use Pdo\Pgsql::copyFromArray() instead in %s on line %d
array (
0 => 1,
1 => 1,
Expand Down
18 changes: 18 additions & 0 deletions ext/pdo_pgsql/tests/copy_to.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ $db->exec('DROP TABLE test_copy_to');
--EXPECTF--
Preparing test table for CopyTo tests
Testing pgsqlCopyToArray() with default parameters

Deprecated: Method PDO::pgsqlCopyToArray() is deprecated since 8.5, use Pdo\Pgsql::copyToArray() instead in %s on line %d
array(3) {
[0]=>
string(19) "0 test insert 0 \N
Expand All @@ -99,6 +101,8 @@ array(3) {
"
}
Testing pgsqlCopyToArray() with different field separator and not null indicator

Deprecated: Method PDO::pgsqlCopyToArray() is deprecated since 8.5, use Pdo\Pgsql::copyToArray() instead in %s on line %d
array(3) {
[0]=>
string(21) "0;test insert 0;NULL
Expand All @@ -111,6 +115,8 @@ array(3) {
"
}
Testing pgsqlCopyToArray() with only selected fields

Deprecated: Method PDO::pgsqlCopyToArray() is deprecated since 8.5, use Pdo\Pgsql::copyToArray() instead in %s on line %d
array(3) {
[0]=>
string(7) "0;NULL
Expand All @@ -123,23 +129,35 @@ array(3) {
"
}
Testing pgsqlCopyToArray() with error

Deprecated: Method PDO::pgsqlCopyToArray() is deprecated since 8.5, use Pdo\Pgsql::copyToArray() instead in %s on line %d
Exception: SQLSTATE[42P01]: Undefined table: 7 %s: %stest_error%s
Testing pgsqlCopyToFile() with default parameters

Deprecated: Method PDO::pgsqlCopyToFile() is deprecated since 8.5, use Pdo\Pgsql::copyToFile() instead in %s on line %d
bool(true)
0 test insert 0 \N
1 test insert 1 \N
2 test insert 2 \N
Testing pgsqlCopyToFile() with different field separator and not null indicator

Deprecated: Method PDO::pgsqlCopyToFile() is deprecated since 8.5, use Pdo\Pgsql::copyToFile() instead in %s on line %d
bool(true)
0;test insert 0;NULL
1;test insert 1;NULL
2;test insert 2;NULL
Testing pgsqlCopyToFile() with only selected fields

Deprecated: Method PDO::pgsqlCopyToFile() is deprecated since 8.5, use Pdo\Pgsql::copyToFile() instead in %s on line %d
bool(true)
0;NULL
1;NULL
2;NULL
Testing pgsqlCopyToFile() with error

Deprecated: Method PDO::pgsqlCopyToFile() is deprecated since 8.5, use Pdo\Pgsql::copyToFile() instead in %s on line %d
Exception: SQLSTATE[42P01]: Undefined table: 7 %s: %stest_error%s
Testing pgsqlCopyToFile() to unwritable file

Deprecated: Method PDO::pgsqlCopyToFile() is deprecated since 8.5, use Pdo\Pgsql::copyToFile() instead in %s on line %d
Exception: SQLSTATE[HY000]: General error: 7 Unable to open the file for writing
23 changes: 22 additions & 1 deletion ext/pdo_pgsql/tests/getnotify.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -84,29 +84,50 @@ var_dump($diff < 1 || abs(1 - abs($diff)) < .05);
var_dump(count($notify));

?>
--EXPECT--
--EXPECTF--
Deprecated: Method PDO::pgsqlGetPid() is deprecated since 8.5, use Pdo\Pgsql::getPid() instead in %s on line %d
bool(true)

Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
bool(false)

Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
bool(false)

Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
int(2)
string(17) "channel_getnotify"
bool(true)

Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
int(2)
string(17) "channel_getnotify"
bool(true)

Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
int(2)
string(17) "channel_getnotify"
bool(true)

Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
int(2)
string(17) "channel_getnotify"
bool(true)

Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
int(4)
string(17) "channel_getnotify"
bool(true)
string(17) "channel_getnotify"
bool(true)

Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
bool(false)

Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
bool(true)
bool(false)

Deprecated: Method PDO::pgsqlGetNotify() is deprecated since 8.5, use Pdo\Pgsql::getNotify() instead in %s on line %d
bool(true)
int(2)
9 changes: 9 additions & 0 deletions ext/pdo_pgsql/tests/gh9411.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,18 @@ var_dump($lob = $db->pgsqlLOBOpen($oid, 'wb'));
var_dump(fgets($lob));
?>
--EXPECTF--
Deprecated: Method PDO::pgsqlLOBCreate() is deprecated since 8.5, use Pdo\Pgsql::lobCreate() instead in %s on line %d

Deprecated: Method PDO::pgsqlLOBOpen() is deprecated since 8.5, use Pdo\Pgsql::lobOpen() instead in %s on line %d
resource(%d) of type (stream)
resource(%d) of type (Unknown)

Deprecated: Method PDO::pgsqlLOBCreate() is deprecated since 8.5, use Pdo\Pgsql::lobCreate() instead in %s on line %d

Deprecated: Method PDO::pgsqlLOBOpen() is deprecated since 8.5, use Pdo\Pgsql::lobOpen() instead in %s on line %d
resource(%d) of type (stream)
resource(%d) of type (Unknown)

Deprecated: Method PDO::pgsqlLOBOpen() is deprecated since 8.5, use Pdo\Pgsql::lobOpen() instead in %s on line %d
resource(%d) of type (stream)
string(4) "test"
7 changes: 6 additions & 1 deletion ext/pdo_pgsql/tests/large_objects.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
$db = PDOTest::test_factory(__DIR__ . '/common.phpt');
$db->exec('DROP TABLE test_large_objects');
?>
--EXPECT--
--EXPECTF--
Deprecated: Method PDO::pgsqlLOBCreate() is deprecated since 8.5, use Pdo\Pgsql::lobCreate() instead in %s on line %d

Deprecated: Method PDO::pgsqlLOBOpen() is deprecated since 8.5, use Pdo\Pgsql::lobOpen() instead in %s on line %d
Fetching:
int(1)
string(11) "Hello dude
Expand All @@ -97,3 +100,5 @@ Fetching NO bind:
int(1)
bool(true)
Fetched!

Deprecated: Method PDO::pgsqlLOBUnlink() is deprecated since 8.5, use Pdo\Pgsql::lobUnlink() instead in %s on line %d
5 changes: 4 additions & 1 deletion ext/pdo_sqlite/tests/bug60104.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ setUp();
setUp();
echo "done";
?>
--EXPECT--
--EXPECTF--
Deprecated: Method PDO::sqliteCreateFunction() is deprecated since 8.5, use Pdo\Sqlite::createFunction() instead in %s on line %d

Deprecated: Method PDO::sqliteCreateFunction() is deprecated since 8.5, use Pdo\Sqlite::createFunction() instead in %s on line %d
done
Loading