1. Backward Incompatible Changes
========================================
+- Fileinfo:
+ . The fileinfo functions now accept and return, respectively, finfo objects
+ instead of resources.
+
- MySQLi:
. mysqli_fetch_fields() and mysqli_fetch_field_direct() will now always return
zero for max_length. You can compute this information by iterating over the
zend_object zo;
} finfo_object;
-#define FILEINFO_DECLARE_INIT_OBJECT(object) \
- zval *object = getThis();
-
static inline finfo_object *php_finfo_fetch_object(zend_object *obj) {
return (finfo_object *)((char*)(obj) - XtOffsetOf(finfo_object, zo));
}
#define Z_FINFO_P(zv) php_finfo_fetch_object(Z_OBJ_P((zv)))
-#define FILEINFO_REGISTER_OBJECT(_object, _ptr) \
-{ \
- finfo_object *obj; \
- obj = Z_FINFO_P(_object); \
- obj->ptr = _ptr; \
-}
-
#define FILEINFO_FROM_OBJECT(finfo, object) \
{ \
finfo_object *obj = Z_FINFO_P(object); \
options, magic_errno(magic), magic_error(magic)); \
RETURN_FALSE; \
}
-
-/* True global resources - no need for thread safety here */
-static int le_fileinfo;
-/* }}} */
-
-void finfo_resource_destructor(zend_resource *rsrc) /* {{{ */
-{
- if (rsrc->ptr) {
- php_fileinfo *finfo = (php_fileinfo *) rsrc->ptr;
- magic_close(finfo->magic);
- efree(rsrc->ptr);
- rsrc->ptr = NULL;
- }
-}
/* }}} */
/* {{{ PHP_MINIT_FUNCTION */
finfo_object_handlers.free_obj = finfo_objects_free;
finfo_object_handlers.clone_obj = NULL;
- le_fileinfo = zend_register_list_destructors_ex(finfo_resource_destructor, NULL, "file_info", module_number);
-
REGISTER_LONG_CONSTANT("FILEINFO_NONE", MAGIC_NONE, CONST_CS|CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("FILEINFO_SYMLINK", MAGIC_SYMLINK, CONST_CS|CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("FILEINFO_MIME", MAGIC_MIME, CONST_CS|CONST_PERSISTENT);
}
/* }}} */
-/* {{{ Create a new fileinfo resource. */
+/* {{{ Construct a new fileinfo object. */
PHP_FUNCTION(finfo_open)
{
zend_long options = MAGIC_NONE;
char *file = NULL;
size_t file_len = 0;
php_fileinfo *finfo;
- FILEINFO_DECLARE_INIT_OBJECT(object)
+ zval *object = getThis();
char resolved_path[MAXPATHLEN];
zend_error_handling zeh;
}
if (object) {
+ finfo_object *obj;
zend_restore_error_handling(&zeh);
- FILEINFO_REGISTER_OBJECT(object, finfo);
+ obj = Z_FINFO_P(object);
+ obj->ptr = finfo;
} else {
- RETURN_RES(zend_register_resource(finfo, le_fileinfo));
+ zend_object *zobj = finfo_objects_new(finfo_class_entry);
+ finfo_object *obj = php_finfo_fetch_object(zobj);
+ obj->ptr = finfo;
+ RETURN_OBJ(zobj);
}
}
/* }}} */
-/* {{{ Close fileinfo resource. */
+/* {{{ Close fileinfo object - a NOP. */
PHP_FUNCTION(finfo_close)
{
- php_fileinfo *finfo;
- zval *zfinfo;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zfinfo) == FAILURE) {
- RETURN_THROWS();
- }
+ zval *self;
- if ((finfo = (php_fileinfo *)zend_fetch_resource(Z_RES_P(zfinfo), "file_info", le_fileinfo)) == NULL) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &self, finfo_class_entry) == FAILURE) {
RETURN_THROWS();
}
- zend_list_close(Z_RES_P(zfinfo));
-
RETURN_TRUE;
}
/* }}} */
{
zend_long options;
php_fileinfo *finfo;
- zval *zfinfo;
- FILEINFO_DECLARE_INIT_OBJECT(object)
+ zval *self;
- if (object) {
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &options) == FAILURE) {
- RETURN_THROWS();
- }
- FILEINFO_FROM_OBJECT(finfo, object);
- } else {
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &zfinfo, &options) == FAILURE) {
- RETURN_THROWS();
- }
- if ((finfo = (php_fileinfo *)zend_fetch_resource(Z_RES_P(zfinfo), "file_info", le_fileinfo)) == NULL) {
- RETURN_THROWS();
- }
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Ol", &self, finfo_class_entry, &options) == FAILURE) {
+ RETURN_THROWS();
}
+ FILEINFO_FROM_OBJECT(finfo, self);
FINFO_SET_OPTION(finfo->magic, options)
finfo->options = options;
char *ret_val = NULL, *buffer = NULL;
size_t buffer_len;
php_fileinfo *finfo = NULL;
- zval *zfinfo, *zcontext = NULL;
+ zval *zcontext = NULL;
zval *what;
char mime_directory[] = "directory";
-
struct magic_set *magic = NULL;
- FILEINFO_DECLARE_INIT_OBJECT(object)
if (mimetype_emu) {
php_error_docref(NULL, E_WARNING, "Failed to load magic database");
goto common;
}
- } else if (object) {
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|lr!", &buffer, &buffer_len, &options, &zcontext) == FAILURE) {
- RETURN_THROWS();
- }
- FILEINFO_FROM_OBJECT(finfo, object);
- magic = finfo->magic;
} else {
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|lr!", &zfinfo, &buffer, &buffer_len, &options, &zcontext) == FAILURE) {
- RETURN_THROWS();
- }
- if ((finfo = (php_fileinfo *)zend_fetch_resource(Z_RES_P(zfinfo), "file_info", le_fileinfo)) == NULL) {
+ zval *self;
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os|lr!", &self, finfo_class_entry, &buffer, &buffer_len, &options, &zcontext) == FAILURE) {
RETURN_THROWS();
}
+ FILEINFO_FROM_OBJECT(finfo, self);
magic = finfo->magic;
}
public function set_flags(int $flags) {}
}
-/** @return resource|false */
-function finfo_open(int $flags = FILEINFO_NONE, string $magic_database = "") {}
+function finfo_open(int $flags = FILEINFO_NONE, string $magic_database = ""): finfo|false {}
-/**
- * @param resource $finfo
- */
-function finfo_close($finfo): bool {}
+function finfo_close(finfo $finfo): bool {}
-/**
- * @param resource $finfo
- */
-function finfo_set_flags($finfo, int $flags): bool {}
+function finfo_set_flags(finfo $finfo, int $flags): bool {}
/**
- * @param resource $finfo
* @param resource|null $context
*/
-function finfo_file($finfo, string $filename, int $flags = FILEINFO_NONE, $context = null): string|false {}
+function finfo_file(finfo $finfo, string $filename, int $flags = FILEINFO_NONE, $context = null): string|false {}
/**
- * @param resource $finfo
* @param resource|null $context
*/
-function finfo_buffer($finfo, string $string, int $flags = FILEINFO_NONE, $context = null): string|false {}
+function finfo_buffer(finfo $finfo, string $string, int $flags = FILEINFO_NONE, $context = null): string|false {}
/**
* @param resource|string $filename
/* This is a generated file, edit the .stub.php file instead.
- * Stub hash: be858509df27550b51d8a7a51a3629eceb6d0aa6 */
+ * Stub hash: 1282a20b1d007bbcc9c0d4efe400db43a5450307 */
-ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_open, 0, 0, 0)
+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")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, magic_database, IS_STRING, 0, "\"\"")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_finfo_close, 0, 1, _IS_BOOL, 0)
- ZEND_ARG_INFO(0, finfo)
+ ZEND_ARG_OBJ_INFO(0, finfo, finfo, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_finfo_set_flags, 0, 2, _IS_BOOL, 0)
- ZEND_ARG_INFO(0, finfo)
+ ZEND_ARG_OBJ_INFO(0, finfo, finfo, 0)
ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_finfo_file, 0, 2, MAY_BE_STRING|MAY_BE_FALSE)
- ZEND_ARG_INFO(0, finfo)
+ ZEND_ARG_OBJ_INFO(0, finfo, finfo, 0)
ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "FILEINFO_NONE")
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, context, "null")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_finfo_buffer, 0, 2, MAY_BE_STRING|MAY_BE_FALSE)
- ZEND_ARG_INFO(0, finfo)
+ ZEND_ARG_OBJ_INFO(0, finfo, finfo, 0)
ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "FILEINFO_NONE")
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, context, "null")
ZEND_ARG_INFO(0, filename)
ZEND_END_ARG_INFO()
-#define arginfo_class_finfo___construct arginfo_finfo_open
+ZEND_BEGIN_ARG_INFO_EX(arginfo_class_finfo___construct, 0, 0, 0)
+ ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "FILEINFO_NONE")
+ ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, magic_database, IS_STRING, 0, "\"\"")
+ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_finfo_file, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0)
?>
--EXPECTF--
bool(false)%A
-resource(%d) of type (file_info)
-resource(%d) of type (file_info)
+object(finfo)#%d (0) {
+}
+object(finfo)#%d (0) {
+}
bool(false)%A
Warning: finfo_open(): offset `string' invalid in %sbug61964-mb.php on line %d
?>
--EXPECTF--
bool(false)%A
-resource(%d) of type (file_info)
-resource(%d) of type (file_info)
+object(finfo)#%d (0) {
+}
+object(finfo)#%d (0) {
+}
bool(false)%A
Warning: finfo_open(): offset `string' invalid in %sbug61964.php on line %d
?>
--EXPECTF--
*** Testing finfo_close() : basic functionality ***
-resource(%d) of type (file_info)
+object(finfo)#%d (0) {
+}
bool(true)
object(finfo)#%d (%d) {
}
*** Testing finfo_close() : error conditions ***
-- Testing finfo_close() function with wrong resource type --
-finfo_close(): supplied resource is not a valid file_info resource
+finfo_close(): Argument #1 ($finfo) must be of type finfo, resource given
?>
--EXPECTF--
finfo_open(): Argument #2 ($magic_database) must not contain any null bytes
-resource(%d) of type (file_info)
-resource(%d) of type (file_info)
+object(finfo)#%d (0) {
+}
+object(finfo)#%d (0) {
+}
Warning: finfo_open(%s123): Failed to open stream: No such file or directory in %s on line %d
?>
--EXPECTF--
*** Testing finfo_open() : basic functionality ***
-resource(%d) of type (file_info)
-resource(%d) of type (file_info)
-resource(%d) of type (file_info)
-resource(%d) of type (file_info)
-resource(%d) of type (file_info)
-resource(%d) of type (file_info)
-resource(%d) of type (file_info)
-object(finfo)#%d (%d) {
-}
-object(finfo)#%d (%d) {
+object(finfo)#%d (0) {
+}
+object(finfo)#%d (0) {
+}
+object(finfo)#%d (0) {
+}
+object(finfo)#%d (0) {
+}
+object(finfo)#%d (0) {
+}
+object(finfo)#%d (0) {
+}
+object(finfo)#%d (0) {
+}
+object(finfo)#%d (0) {
+}
+object(finfo)#%d (0) {
}
--TEST--
Test finfo_open() function : error functionality
--SKIPIF--
-<?php require_once(__DIR__ . '/skipif.inc');
+<?php require_once(__DIR__ . '/skipif.inc')?>
--FILE--
<?php
$magicFile = __DIR__ . DIRECTORY_SEPARATOR . 'magic';
bool(false)
Warning: finfo_open(): using regular magic file `%smagic' in %sfinfo_open_error.php on line %d
-resource(6) of type (file_info)
+object(finfo)#%d (0) {
+}
finfo_open(): Argument #1 ($flags) must be of type int, string given
finfo::__construct(): Argument #1 ($flags) must be of type int, string given
?>
--EXPECTF--
*** Testing finfo_open() : variations in opening ***
-resource(%d) of type (file_info)
-resource(%d) of type (file_info)
+object(finfo)#%d (0) {
+}
+object(finfo)#%d (0) {
+}
#endif
/* ext/fileinfo */
- F1("finfo_open", MAY_BE_FALSE | MAY_BE_RESOURCE),
+ F1("finfo_open", MAY_BE_FALSE | MAY_BE_OBJECT),
F1("finfo_file", MAY_BE_FALSE | MAY_BE_STRING),
F1("finfo_buffer", MAY_BE_FALSE | MAY_BE_STRING),
F1("mime_content_type", MAY_BE_FALSE | MAY_BE_STRING),