From bad3cef4ae3f2231ffb22a44579be5cc91f20954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 22 Apr 2025 20:29:14 +0200 Subject: [PATCH] fileinfo: Deprecate `finfo_close()` This is for consistency with other `*_close()` functions that have become obsolete when migrating from resources to objects. --- ext/fileinfo/fileinfo.c | 3 ++- ext/fileinfo/fileinfo.stub.php | 1 + ext/fileinfo/fileinfo_arginfo.h | 17 +++++++++++++++-- ext/fileinfo/tests/finfo_close_basic.phpt | 2 ++ ext/fileinfo/tests/finfo_close_error.phpt | 4 +++- 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/ext/fileinfo/fileinfo.c b/ext/fileinfo/fileinfo.c index 143b8ba080fc5..32062331525bc 100644 --- a/ext/fileinfo/fileinfo.c +++ b/ext/fileinfo/fileinfo.c @@ -31,10 +31,11 @@ #include "php_ini.h" #include "ext/standard/info.h" #include "ext/standard/file.h" /* needed for context stuff */ +#include "Zend/zend_attributes.h" +#include "Zend/zend_exceptions.h" #include "php_fileinfo.h" #include "fileinfo_arginfo.h" #include "fopen_wrappers.h" /* needed for is_url */ -#include "Zend/zend_exceptions.h" static zend_object_handlers finfo_object_handlers; zend_class_entry *finfo_class_entry; diff --git a/ext/fileinfo/fileinfo.stub.php b/ext/fileinfo/fileinfo.stub.php index 2dba0fe2659ef..238ad7c14809b 100644 --- a/ext/fileinfo/fileinfo.stub.php +++ b/ext/fileinfo/fileinfo.stub.php @@ -92,6 +92,7 @@ public function set_flags(int $flags): true {} /** @refcount 1 */ function finfo_open(int $flags = FILEINFO_NONE, ?string $magic_database = null): finfo|false {} +#[\Deprecated(since: '8.5', message: 'as finfo objects are freed automatically')] function finfo_close(finfo $finfo): true {} function finfo_set_flags(finfo $finfo, int $flags): true {} diff --git a/ext/fileinfo/fileinfo_arginfo.h b/ext/fileinfo/fileinfo_arginfo.h index 024e7d4b6bd59..9bca7573da048 100644 --- a/ext/fileinfo/fileinfo_arginfo.h +++ b/ext/fileinfo/fileinfo_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: d5bc322159e4af87077c07ddaca0a77803b4743a */ + * Stub hash: 311d1049e32af017b44e260a00f13830714b1e96 */ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_finfo_open, 0, 0, finfo, MAY_BE_FALSE) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "FILEINFO_NONE") @@ -63,7 +63,7 @@ ZEND_FUNCTION(mime_content_type); static const zend_function_entry ext_functions[] = { ZEND_FE(finfo_open, arginfo_finfo_open) - ZEND_FE(finfo_close, arginfo_finfo_close) + ZEND_RAW_FENTRY("finfo_close", zif_finfo_close, arginfo_finfo_close, ZEND_ACC_DEPRECATED, NULL, NULL) ZEND_FE(finfo_set_flags, arginfo_finfo_set_flags) ZEND_FE(finfo_file, arginfo_finfo_file) ZEND_FE(finfo_buffer, arginfo_finfo_buffer) @@ -96,6 +96,19 @@ static void register_fileinfo_symbols(int module_number) #endif REGISTER_LONG_CONSTANT("FILEINFO_APPLE", MAGIC_APPLE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("FILEINFO_EXTENSION", MAGIC_EXTENSION, CONST_PERSISTENT); + + + zend_attribute *attribute_Deprecated_func_finfo_close_0 = zend_add_function_attribute(zend_hash_str_find_ptr(CG(function_table), "finfo_close", sizeof("finfo_close") - 1), ZSTR_KNOWN(ZEND_STR_DEPRECATED_CAPITALIZED), 2); + zval attribute_Deprecated_func_finfo_close_0_arg0; + zend_string *attribute_Deprecated_func_finfo_close_0_arg0_str = zend_string_init("8.5", strlen("8.5"), 1); + ZVAL_STR(&attribute_Deprecated_func_finfo_close_0_arg0, attribute_Deprecated_func_finfo_close_0_arg0_str); + ZVAL_COPY_VALUE(&attribute_Deprecated_func_finfo_close_0->args[0].value, &attribute_Deprecated_func_finfo_close_0_arg0); + attribute_Deprecated_func_finfo_close_0->args[0].name = ZSTR_KNOWN(ZEND_STR_SINCE); + zval attribute_Deprecated_func_finfo_close_0_arg1; + zend_string *attribute_Deprecated_func_finfo_close_0_arg1_str = zend_string_init("as finfo objects are freed automatically", strlen("as finfo objects are freed automatically"), 1); + ZVAL_STR(&attribute_Deprecated_func_finfo_close_0_arg1, attribute_Deprecated_func_finfo_close_0_arg1_str); + ZVAL_COPY_VALUE(&attribute_Deprecated_func_finfo_close_0->args[1].value, &attribute_Deprecated_func_finfo_close_0_arg1); + attribute_Deprecated_func_finfo_close_0->args[1].name = ZSTR_KNOWN(ZEND_STR_MESSAGE); } static zend_class_entry *register_class_finfo(void) diff --git a/ext/fileinfo/tests/finfo_close_basic.phpt b/ext/fileinfo/tests/finfo_close_basic.phpt index cdaf4b23b0002..1abd7216390dc 100644 --- a/ext/fileinfo/tests/finfo_close_basic.phpt +++ b/ext/fileinfo/tests/finfo_close_basic.phpt @@ -23,6 +23,8 @@ unset( $finfo ); *** Testing finfo_close() : basic functionality *** object(finfo)#%d (0) { } + +Deprecated: Function finfo_close() is deprecated since 8.5, as finfo objects are freed automatically in %s on line %d bool(true) object(finfo)#%d (%d) { } diff --git a/ext/fileinfo/tests/finfo_close_error.phpt b/ext/fileinfo/tests/finfo_close_error.phpt index c43597f26a4e5..c7873b462724e 100644 --- a/ext/fileinfo/tests/finfo_close_error.phpt +++ b/ext/fileinfo/tests/finfo_close_error.phpt @@ -15,8 +15,10 @@ try { } ?> ---EXPECT-- +--EXPECTF-- *** Testing finfo_close() : error conditions *** -- Testing finfo_close() function with wrong resource type -- + +Deprecated: Function finfo_close() is deprecated since 8.5, as finfo objects are freed automatically in %s on line %d finfo_close(): Argument #1 ($finfo) must be of type finfo, resource given