php_zip icon indicating copy to clipboard operation
php_zip copied to clipboard

Inconsistent error reporting in ZipArchive::extractTo()

Open philipp-kolesnikov opened this issue 3 years ago • 1 comments

According to ZipArchive::extractTo documentation method "Returns true on success or false on failure". In some cases I get ValueError instead of false.

This was behavior introduced in PHP 8:

#define ZIP_FROM_OBJECT(intern, object) \
	{ \
		ze_zip_object *obj = Z_ZIP_P(object); \
		intern = obj->za; \
		if (!intern) { \
			zend_value_error("Invalid or uninitialized Zip object"); \
			RETURN_THROWS(); \
		} \
	}
/* }}} */

While it still returns false in PHP 7:

/* {{{ ZIP_FROM_OBJECT */
#define ZIP_FROM_OBJECT(intern, object) \
	{ \
		ze_zip_object *obj = Z_ZIP_P(object); \
		intern = obj->za; \
		if (!intern) { \
			php_error_docref(NULL, E_WARNING, "Invalid or uninitialized Zip object"); \
			RETURN_FALSE; \
		} \
	}
/* }}} */

I'm not sure if this a documentation or code issue.

philipp-kolesnikov avatar Dec 10 '21 00:12 philipp-kolesnikov

Warning promoted to exception is a general PHP 8 feature, not specific to this extension.

remicollet avatar Dec 10 '21 06:12 remicollet