summaryrefslogtreecommitdiff
path: root/ext/fileinfo/fileinfo.c
diff options
context:
space:
mode:
authorNikita Popov <nikic@php.net>2015-04-02 18:52:32 +0200
committerNikita Popov <nikic@php.net>2015-04-06 11:27:34 +0200
commit122d759618a42bff105971b923fbbb5be02e34b9 (patch)
treefd4487414ffa3f120c77b19b9eb7dc409659c57e /ext/fileinfo/fileinfo.c
parent884b0365dbe718f667d048dbc3d1cd9d9f12ab84 (diff)
downloadphp-git-122d759618a42bff105971b923fbbb5be02e34b9.tar.gz
Always throw TypeException on throwing zpp failures
Introduces a ZEND_PARSE_PARAMS_THROW flag for zpp, which forces to report FAILURE errors using a TypeException instead of a Warning, like it would happen in strict mode. Adds a zend_parse_parameters_throw() convenience function, which invokes zpp with this flag. Converts all cases I could identify, where we currently have throwing zpp usage in constructors and replaces them with this API. Error handling is still replaced to EH_THROW in some cases to handle other, domain-specific errors in constructors.
Diffstat (limited to 'ext/fileinfo/fileinfo.c')
-rw-r--r--ext/fileinfo/fileinfo.c14
1 files changed, 4 insertions, 10 deletions
diff --git a/ext/fileinfo/fileinfo.c b/ext/fileinfo/fileinfo.c
index 975a0db4c1..c4745f92fe 100644
--- a/ext/fileinfo/fileinfo.c
+++ b/ext/fileinfo/fileinfo.c
@@ -294,23 +294,17 @@ PHP_FUNCTION(finfo_open)
FILEINFO_DECLARE_INIT_OBJECT(object)
char resolved_path[MAXPATHLEN];
zend_error_handling zeh;
+ int flags = object ? ZEND_PARSE_PARAMS_THROW : 0;
- if (object) {
- zend_replace_error_handling(EH_THROW, NULL, &zeh);
- }
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "|lp", &options, &file, &file_len) == FAILURE) {
- if (object) {
- zend_restore_error_handling(&zeh);
- if (!EG(exception)) {
- zend_throw_exception(NULL, "Constructor failed", 0);
- }
- }
+ if (zend_parse_parameters_ex(flags, ZEND_NUM_ARGS(), "|lp", &options, &file, &file_len) == FAILURE) {
RETURN_FALSE;
}
if (object) {
finfo_object *finfo_obj = Z_FINFO_P(object);
+ zend_replace_error_handling(EH_THROW, NULL, &zeh);
+
if (finfo_obj->ptr) {
magic_close(finfo_obj->ptr->magic);
efree(finfo_obj->ptr);