]> granicus.if.org Git - php/commitdiff
Always throw TypeException on throwing zpp failures
authorNikita Popov <nikic@php.net>
Thu, 2 Apr 2015 16:52:32 +0000 (18:52 +0200)
committerNikita Popov <nikic@php.net>
Mon, 6 Apr 2015 09:27:34 +0000 (11:27 +0200)
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.

88 files changed:
Zend/zend.c
Zend/zend.h
Zend/zend_API.c
Zend/zend_API.h
ext/date/php_date.c
ext/date/tests/DateTimeZone_construct_error.phpt
ext/date/tests/DateTimeZone_construct_variation1.phpt
ext/date/tests/DateTime_construct_error.phpt
ext/date/tests/DateTime_construct_variation1.phpt
ext/date/tests/DateTime_construct_variation2.phpt
ext/dom/attr.c
ext/dom/cdatasection.c
ext/dom/comment.c
ext/dom/document.c
ext/dom/documentfragment.c
ext/dom/element.c
ext/dom/entityreference.c
ext/dom/processinginstruction.c
ext/dom/tests/DOMAttr_construct_error_001.phpt
ext/dom/tests/DOMCDATASection_construct_error_001.phpt
ext/dom/tests/DOMComment_construct_error_001.phpt
ext/dom/tests/DOMDocumentFragment_construct_error_001.phpt
ext/dom/text.c
ext/dom/xpath.c
ext/fileinfo/fileinfo.c
ext/fileinfo/tests/bug61173.phpt
ext/fileinfo/tests/finfo_open_error.phpt
ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp
ext/intl/calendar/gregoriancalendar_methods.cpp
ext/intl/collator/collator_create.c
ext/intl/converter/converter.c
ext/intl/dateformat/dateformat_create.cpp
ext/intl/formatter/formatter_main.c
ext/intl/intl_error.c
ext/intl/intl_error.h
ext/intl/msgformat/msgformat.c
ext/intl/resourcebundle/resourcebundle_class.c
ext/intl/spoofchecker/spoofchecker_create.c
ext/intl/tests/breakiter___construct_error.phpt
ext/intl/tests/formatter_fail.phpt
ext/intl/tests/gregoriancalendar___construct_error.phpt
ext/intl/tests/msgfmt_fail.phpt
ext/intl/tests/msgfmt_fail2.phpt
ext/pdo/pdo_dbh.c
ext/pdo_mysql/tests/pdo_mysql___construct.phpt
ext/pdo_mysql/tests/pdo_mysql___construct_options.phpt
ext/phar/phar_object.c
ext/phar/tests/badparameters.phpt
ext/phar/tests/bug60261.phpt
ext/phar/tests/pharfileinfo_construct.phpt
ext/reflection/php_reflection.c
ext/reflection/tests/ReflectionExtension_constructor_error.phpt
ext/reflection/tests/ReflectionFunction_construct.001.phpt
ext/reflection/tests/ReflectionMethod_006.phpt
ext/reflection/tests/ReflectionMethod_constructor_error2.phpt
ext/reflection/tests/ReflectionParameter_invalidMethodInConstructor.phpt
ext/reflection/tests/ReflectionProperty_error.phpt
ext/simplexml/simplexml.c
ext/snmp/snmp.c
ext/spl/spl_array.c
ext/spl/spl_directory.c
ext/spl/spl_fixedarray.c
ext/spl/spl_iterators.c
ext/spl/spl_observer.c
ext/spl/tests/CallbackFilterIteratorTest-002.phpt
ext/spl/tests/SplFixedArray__construct_param_array.phpt
ext/spl/tests/SplFixedArray__construct_param_string.phpt
ext/spl/tests/SplFixedArray_construct_param_SplFixedArray.phpt
ext/spl/tests/SplTempFileObject_constructor_error.phpt
ext/spl/tests/arrayObject___construct_error1.phpt
ext/spl/tests/arrayObject___construct_error2.phpt
ext/spl/tests/arrayObject_setIteratorClass_error1.phpt
ext/spl/tests/bug54292.phpt
ext/spl/tests/fixedarray_005.phpt
ext/spl/tests/fixedarray_009.phpt
ext/spl/tests/fixedarray_015.phpt
ext/spl/tests/iterator_056.phpt
ext/spl/tests/iterator_059.phpt [deleted file]
ext/spl/tests/iterator_060.phpt [deleted file]
ext/spl/tests/iterator_061.phpt [deleted file]
ext/spl/tests/iterator_063.phpt [deleted file]
ext/spl/tests/iterator_064.phpt [deleted file]
ext/spl/tests/iterator_065.phpt [deleted file]
ext/spl/tests/iterator_066.phpt [deleted file]
ext/spl/tests/recursive_tree_iterator_003.phpt
ext/spl/tests/spl_iterator_iterator_constructor.phpt
ext/sqlite3/sqlite3.c
ext/sqlite3/tests/sqlite3_02_open.phpt

index 99e560ac035218b23f856bd0545bae26eebc4d91..a7d456876add73c84fc534ebe7872057aaf14632 100644 (file)
@@ -1316,14 +1316,14 @@ ZEND_API void zend_type_error(const char *format, ...) /* {{{ */
        va_end(va);
 } /* }}} */
 
-ZEND_API void zend_internal_type_error(zend_bool strict, const char *format, ...) /* {{{ */
+ZEND_API void zend_internal_type_error(zend_bool throw_exception, const char *format, ...) /* {{{ */
 {
        va_list va;
        char *message = NULL;
 
        va_start(va, format);
        zend_vspprintf(&message, 0, format, va);
-       if (strict) {
+       if (throw_exception) {
                zend_throw_exception(zend_get_type_exception(), message, E_ERROR);
        } else {
                zend_error(E_WARNING, message);
index db132a583a54360ce97e6f568758694026656053..a9e65ae7ed47d609629cf381e96a9f836d0b46fc 100644 (file)
@@ -286,7 +286,7 @@ extern ZEND_API zend_string *(*zend_resolve_path)(const char *filename, int file
 
 ZEND_API void zend_error(int type, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
 ZEND_API void zend_type_error(const char *format, ...);
-ZEND_API void zend_internal_type_error(zend_bool strict, const char *format, ...);
+ZEND_API void zend_internal_type_error(zend_bool throw_exception, const char *format, ...);
 
 void zenderror(const char *error);
 
index 8cd7ddd5d627a896120f8bab59b1a32d6250b1f6..273e9e9f6ab6c0e37d110f9a6dc45f3798603f15 100644 (file)
@@ -761,13 +761,16 @@ static int zend_parse_arg(int arg_num, zval *arg, va_list *va, const char **spec
                if (!(flags & ZEND_PARSE_PARAMS_QUIET) && (*expected_type || error)) {
                        const char *space;
                        const char *class_name = get_active_class_name(&space);
+                       zend_bool throw_exception =
+                               ZEND_ARG_USES_STRICT_TYPES() || (flags & ZEND_PARSE_PARAMS_THROW);
 
                        if (error) {
-                               zend_internal_type_error(ZEND_ARG_USES_STRICT_TYPES(), "%s%s%s() expects parameter %d %s",
-                                                       class_name, space, get_active_function_name(), arg_num, error);
+                               zend_internal_type_error(throw_exception, "%s%s%s() expects parameter %d %s",
+                                               class_name, space, get_active_function_name(), arg_num, error);
                                efree(error);
                        } else {
-                               zend_internal_type_error(ZEND_ARG_USES_STRICT_TYPES(), "%s%s%s() expects parameter %d to be %s, %s given",
+                               zend_internal_type_error(throw_exception,
+                                               "%s%s%s() expects parameter %d to be %s, %s given",
                                                class_name, space, get_active_function_name(), arg_num, expected_type,
                                                zend_zval_type_name(arg));
                        }
@@ -876,7 +879,9 @@ static int zend_parse_va_args(int num_args, const char *type_spec, va_list *va,
                if (!(flags & ZEND_PARSE_PARAMS_QUIET)) {
                        zend_function *active_function = EG(current_execute_data)->func;
                        const char *class_name = active_function->common.scope ? active_function->common.scope->name->val : "";
-                       zend_internal_type_error(ZEND_ARG_USES_STRICT_TYPES(), "%s%s%s() expects %s %d parameter%s, %d given",
+                       zend_bool throw_exception =
+                               ZEND_ARG_USES_STRICT_TYPES() || (flags & ZEND_PARSE_PARAMS_THROW);
+                       zend_internal_type_error(throw_exception, "%s%s%s() expects %s %d parameter%s, %d given",
                                        class_name,
                                        class_name[0] ? "::" : "",
                                        active_function->common.function_name->val,
@@ -938,18 +943,19 @@ static int zend_parse_va_args(int num_args, const char *type_spec, va_list *va,
 }
 /* }}} */
 
-#define RETURN_IF_ZERO_ARGS(num_args, type_spec, flags) { \
+#define RETURN_IF_ZERO_ARGS(num_args, type_spec, flags) do { \
        int __num_args = (num_args); \
-       \
        if (0 == (type_spec)[0] && 0 != __num_args && !(flags & ZEND_PARSE_PARAMS_QUIET)) { \
                const char *__space; \
                const char * __class_name = get_active_class_name(&__space); \
-               zend_internal_type_error(ZEND_ARG_USES_STRICT_TYPES(), "%s%s%s() expects exactly 0 parameters, %d given", \
-                       __class_name, __space, \
-                       get_active_function_name(), __num_args); \
+               zend_bool throw_exception = \
+                       ZEND_ARG_USES_STRICT_TYPES() || (flags & ZEND_PARSE_PARAMS_THROW); \
+               zend_internal_type_error(throw_exception, \
+                       "%s%s%s() expects exactly 0 parameters, %d given", \
+                       __class_name, __space, get_active_function_name(), __num_args); \
                return FAILURE; \
-       }\
-}
+       } \
+} while(0)
 
 ZEND_API int zend_parse_parameters_ex(int flags, int num_args, const char *type_spec, ...) /* {{{ */
 {
@@ -982,6 +988,22 @@ ZEND_API int zend_parse_parameters(int num_args, const char *type_spec, ...) /*
 }
 /* }}} */
 
+ZEND_API int zend_parse_parameters_throw(int num_args, const char *type_spec, ...) /* {{{ */
+{
+       va_list va;
+       int retval;
+       int flags = ZEND_PARSE_PARAMS_THROW;
+
+       RETURN_IF_ZERO_ARGS(num_args, type_spec, flags);
+
+       va_start(va, type_spec);
+       retval = zend_parse_va_args(num_args, type_spec, &va, flags);
+       va_end(va);
+
+       return retval;
+}
+/* }}} */
+
 ZEND_API int zend_parse_method_parameters(int num_args, zval *this_ptr, const char *type_spec, ...) /* {{{ */
 {
        va_list va;
index 23ec35f00c37fe0b500c8f99581ee285feb9c2da..a09d634ee7de82a31e27ca9f735b073326b5a20e 100644 (file)
@@ -257,8 +257,10 @@ ZEND_API int zend_copy_parameters_array(int param_count, zval *argument_array);
 /* Parameter parsing API -- andrei */
 
 #define ZEND_PARSE_PARAMS_QUIET (1<<1)
+#define ZEND_PARSE_PARAMS_THROW (1<<2)
 ZEND_API int zend_parse_parameters(int num_args, const char *type_spec, ...);
 ZEND_API int zend_parse_parameters_ex(int flags, int num_args, const char *type_spec, ...);
+ZEND_API int zend_parse_parameters_throw(int num_args, const char *type_spec, ...);
 ZEND_API char *zend_zval_type_name(const zval *arg);
 
 ZEND_API int zend_parse_method_parameters(int num_args, zval *this_ptr, const char *type_spec, ...);
index 8c6b2e5a1fe0effc53baae9b749dc9230cb79717..959ab4896c4105af3f28ba6b8e4fcdf0fb90ca60 100644 (file)
@@ -2663,10 +2663,12 @@ PHP_METHOD(DateTime, __construct)
        size_t time_str_len = 0;
        zend_error_handling error_handling;
 
-       zend_replace_error_handling(EH_THROW, NULL, &error_handling);
-       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|sO!", &time_str, &time_str_len, &timezone_object, date_ce_timezone)) {
-               php_date_initialize(Z_PHPDATE_P(getThis()), time_str, time_str_len, NULL, timezone_object, 1);
+       if (FAILURE == zend_parse_parameters_throw(ZEND_NUM_ARGS(), "|sO!", &time_str, &time_str_len, &timezone_object, date_ce_timezone)) {
+               return;
        }
+
+       zend_replace_error_handling(EH_THROW, NULL, &error_handling);
+       php_date_initialize(Z_PHPDATE_P(getThis()), time_str, time_str_len, NULL, timezone_object, 1);
        zend_restore_error_handling(&error_handling);
 }
 /* }}} */
@@ -2681,10 +2683,12 @@ PHP_METHOD(DateTimeImmutable, __construct)
        size_t time_str_len = 0;
        zend_error_handling error_handling;
 
-       zend_replace_error_handling(EH_THROW, NULL, &error_handling);
-       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|sO!", &time_str, &time_str_len, &timezone_object, date_ce_timezone)) {
-               php_date_initialize(Z_PHPDATE_P(getThis()), time_str, time_str_len, NULL, timezone_object, 1);
+       if (FAILURE == zend_parse_parameters_throw(ZEND_NUM_ARGS(), "|sO!", &time_str, &time_str_len, &timezone_object, date_ce_timezone)) {
+               return;
        }
+
+       zend_replace_error_handling(EH_THROW, NULL, &error_handling);
+       php_date_initialize(Z_PHPDATE_P(getThis()), time_str, time_str_len, NULL, timezone_object, 1);
        zend_restore_error_handling(&error_handling);
 }
 /* }}} */
@@ -3641,11 +3645,13 @@ PHP_METHOD(DateTimeZone, __construct)
        php_timezone_obj *tzobj;
        zend_error_handling error_handling;
 
-       zend_replace_error_handling(EH_THROW, NULL, &error_handling);
-       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &tz, &tz_len)) {
-               tzobj = Z_PHPTIMEZONE_P(getThis());
-               timezone_initialize(tzobj, tz);
+       if (FAILURE == zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &tz, &tz_len)) {
+               return;
        }
+
+       zend_replace_error_handling(EH_THROW, NULL, &error_handling);
+       tzobj = Z_PHPTIMEZONE_P(getThis());
+       timezone_initialize(tzobj, tz);
        zend_restore_error_handling(&error_handling);
 }
 /* }}} */
@@ -4070,13 +4076,15 @@ PHP_METHOD(DateInterval, __construct)
        timelib_rel_time *reltime;
        zend_error_handling error_handling;
 
+       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &interval_string, &interval_string_length) == FAILURE) {
+               return;
+       }
+
        zend_replace_error_handling(EH_THROW, NULL, &error_handling);
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &interval_string, &interval_string_length) == SUCCESS) {
-               if (date_interval_initialize(&reltime, interval_string, interval_string_length) == SUCCESS) {
-                       diobj = Z_PHPINTERVAL_P(getThis());
-                       diobj->diff = reltime;
-                       diobj->initialized = 1;
-               }
+       if (date_interval_initialize(&reltime, interval_string, interval_string_length) == SUCCESS) {
+               diobj = Z_PHPINTERVAL_P(getThis());
+               diobj->diff = reltime;
+               diobj->initialized = 1;
        }
        zend_restore_error_handling(&error_handling);
 }
index 8ffe32217603cd89c9f2917018b5eabf5b5cd410..6ff900d82fefa38d3ce94b372a935ffa431904d8 100644 (file)
@@ -15,7 +15,11 @@ echo "*** Testing DateTimeZone() : error conditions ***\n";
 echo "\n-- Testing new DateTimeZone() with more than expected no. of arguments --\n";
 $timezone = "GMT";
 $extra_arg = 99;
-var_dump( new DateTimeZone($timezone, $extra_arg) );
+try {
+    new DateTimeZone($timezone, $extra_arg);
+} catch (TypeException $e) {
+    echo $e->getMessage(), "\n";
+}
 
 ?>
 ===DONE===
@@ -23,10 +27,5 @@ var_dump( new DateTimeZone($timezone, $extra_arg) );
 *** Testing DateTimeZone() : error conditions ***
 
 -- Testing new DateTimeZone() with more than expected no. of arguments --
-
-Fatal error: Uncaught exception 'Exception' with message 'DateTimeZone::__construct() expects exactly 1 parameter, 2 given' in %s:%d
-Stack trace:
-#0 %s(%d): DateTimeZone->__construct('GMT', 99)
-#1 {main}
-  thrown in %s on line %d
-  
\ No newline at end of file
+DateTimeZone::__construct() expects exactly 1 parameter, 2 given
+===DONE===
index 025c6e2678eb52c86572444135956a375f8c1d16..96f5372611a84669111e2e840d7b14abf89729fb 100644 (file)
@@ -97,7 +97,7 @@ foreach($inputs as $variation =>$timezone) {
       echo "\n-- $variation --\n";
       try {
        var_dump( new DateTimezone($timezone) );
-      } catch(Exception $e) {
+      } catch (BaseException $e) {
          $msg = $e->getMessage();
          echo "FAILED: " . $msg . "\n";
       }        
index ef79eb45549d7724598e1f9ae1d78ea1a38e54eb..de42566961e6ae63fb4323b6e0c47cbb632d928b 100644 (file)
@@ -16,7 +16,11 @@ echo "\n-- Testing new DateTime() with more than expected no. of arguments --\n"
 $time = "GMT";
 $timezone  = timezone_open("GMT");
 $extra_arg = 99;
-var_dump( new DateTime($time, $timezone, $extra_arg) );
+try {
+    var_dump( new DateTime($time, $timezone, $extra_arg) );
+} catch (TypeException $e) {
+    echo $e->getMessage(), "\n";
+}
 
 ?>
 ===DONE===
@@ -24,9 +28,5 @@ var_dump( new DateTime($time, $timezone, $extra_arg) );
 *** Testing date_create() : error conditions ***
 
 -- Testing new DateTime() with more than expected no. of arguments --
-
-Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct() expects at most 2 parameters, 3 given' in %s:%d
-Stack trace:
-#0 %s(%d): DateTime->__construct('GMT', Object(DateTimeZone), 99)
-#1 {main}
-  thrown in %s on line %d
\ No newline at end of file
+DateTime::__construct() expects at most 2 parameters, 3 given
+===DONE===
index f106a409350fa953f4f5d32301658af36915acfa..6f149ae2075786cd60c1267f4519d6e2871ab4f5 100644 (file)
@@ -102,14 +102,14 @@ foreach($inputs as $variation =>$time) {
       
       try {
        var_dump( new DateTime($time) );
-      } catch(Exception $e) {
+      } catch (BaseException $e) {
          $msg = $e->getMessage();
          echo "FAILED: " . $msg . "\n";
       }        
       
       try {
        var_dump( new DateTime($time, $timezone) );
-      } catch(Exception$e) {
+      } catch (BaseException$e) {
         $msg = $e->getMessage();
         echo "FAILED: " . $msg . "\n";
       }        
index e24788b0664896d3139839fa299784756c1f8d1f..d134d8f6cf33ba8062279f34714f45c9fe928470 100644 (file)
@@ -102,7 +102,7 @@ foreach($inputs as $variation =>$timezone) {
       
       try {
                        var_dump( new DateTime($time, $timezone) );
-      } catch(Exception $e) {
+      } catch (BaseException $e) {
                        $msg = $e->getMessage();
                        echo "FAILED: " . $msg . "\n";
       }        
index 05bfc542323c06a82bed6deb105bf46a13b894c7..1ecf6610b748b018e44356efee7b585bb3b3a2bc 100644 (file)
@@ -55,21 +55,17 @@ const zend_function_entry php_dom_attr_class_functions[] = {
 /* {{{ proto void DOMAttr::__construct(string name, [string value]); */
 PHP_METHOD(domattr, __construct)
 {
-       zval *id;
+       zval *id = getThis();
        xmlAttrPtr nodep = NULL;
        xmlNodePtr oldnode = NULL;
        dom_object *intern;
        char *name, *value = NULL;
        size_t name_len, value_len, name_valid;
-       zend_error_handling error_handling;
 
-       zend_replace_error_handling(EH_THROW, dom_domexception_class_entry, &error_handling);
-       if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os|s", &id, dom_attr_class_entry, &name, &name_len, &value, &value_len) == FAILURE) {
-               zend_restore_error_handling(&error_handling);
+       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s|s", &name, &name_len, &value, &value_len) == FAILURE) {
                return;
        }
 
-       zend_restore_error_handling(&error_handling);
        intern = Z_DOMOBJ_P(id);
 
        name_valid = xmlValidateName((xmlChar *) name, 0);
index 5bdc5ba11be054c35f18059d0d7613944c60147f..e6b7e33bcebf93315dfd30eb453bff194b22e52b 100644 (file)
@@ -50,20 +50,16 @@ const zend_function_entry php_dom_cdatasection_class_functions[] = {
 PHP_METHOD(domcdatasection, __construct)
 {
 
-       zval *id;
+       zval *id = getThis();
        xmlNodePtr nodep = NULL, oldnode = NULL;
        dom_object *intern;
        char *value = NULL;
        size_t value_len;
-       zend_error_handling error_handling;
 
-       zend_replace_error_handling(EH_THROW, dom_domexception_class_entry, &error_handling);
-       if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &id, dom_cdatasection_class_entry, &value, &value_len) == FAILURE) {
-               zend_restore_error_handling(&error_handling);
+       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &value, &value_len) == FAILURE) {
                return;
        }
 
-       zend_restore_error_handling(&error_handling);
        nodep = xmlNewCDataBlock(NULL, (xmlChar *) value, value_len);
 
        if (!nodep) {
index 01ed295e4748d7c884a1cea933ba1e2607f1aeb8..4dc016ae3b23498d29e8feb9ebd11469e2042293 100644 (file)
@@ -50,20 +50,16 @@ const zend_function_entry php_dom_comment_class_functions[] = {
 PHP_METHOD(domcomment, __construct)
 {
 
-       zval *id;
+       zval *id = getThis();
        xmlNodePtr nodep = NULL, oldnode = NULL;
        dom_object *intern;
        char *value = NULL;
        size_t value_len;
-       zend_error_handling error_handling;
 
-       zend_replace_error_handling(EH_THROW, dom_domexception_class_entry, &error_handling);
-       if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|s", &id, dom_comment_class_entry, &value, &value_len) == FAILURE) {
-               zend_restore_error_handling(&error_handling);
+       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "|s", &value, &value_len) == FAILURE) {
                return;
        }
 
-       zend_restore_error_handling(&error_handling);
        nodep = xmlNewComment((xmlChar *) value);
 
        if (!nodep) {
index bcd81c0d9b354d1d7b9306b5978ad227c3231022..92d5fb5d3349ab2de3f93a183a80f74e424f0d1c 100644 (file)
@@ -1253,21 +1253,17 @@ PHP_FUNCTION(dom_document_rename_node)
 PHP_METHOD(domdocument, __construct)
 {
 
-       zval *id;
+       zval *id = getThis();
        xmlDoc *docp = NULL, *olddoc;
        dom_object *intern;
        char *encoding, *version = NULL;
        size_t encoding_len = 0, version_len = 0;
        int refcount;
-       zend_error_handling error_handling;
 
-       zend_replace_error_handling(EH_THROW, dom_domexception_class_entry, &error_handling);
-       if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|ss", &id, dom_document_class_entry, &version, &version_len, &encoding, &encoding_len) == FAILURE) {
-               zend_restore_error_handling(&error_handling);
+       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "|ss", &version, &version_len, &encoding, &encoding_len) == FAILURE) {
                return;
        }
 
-       zend_restore_error_handling(&error_handling);
        docp = xmlNewDoc((xmlChar *) version);
 
        if (!docp) {
index 31d3065f50d13372131d82d3df2fefacd774b5aa..9cf0fd5423aa6887be7c6e1918bbc1ed6f654e5d 100644 (file)
@@ -53,18 +53,14 @@ const zend_function_entry php_dom_documentfragment_class_functions[] = {
 PHP_METHOD(domdocumentfragment, __construct)
 {
 
-       zval *id;
+       zval *id = getThis();
        xmlNodePtr nodep = NULL, oldnode = NULL;
        dom_object *intern;
-       zend_error_handling error_handling;
 
-       zend_replace_error_handling(EH_THROW, dom_domexception_class_entry, &error_handling);
-       if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &id, dom_documentfragment_class_entry) == FAILURE) {
-               zend_restore_error_handling(&error_handling);
+       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "") == FAILURE) {
                return;
        }
 
-       zend_restore_error_handling(&error_handling);
        nodep = xmlNewDocFragment(NULL);
 
        if (!nodep) {
index b05237ff392783247cff17f34d204685fc0d6727..4af6c9accf4c391c52bedc0da0d42199f48ad791 100644 (file)
@@ -154,7 +154,7 @@ const zend_function_entry php_dom_element_class_functions[] = { /* {{{ */
 PHP_METHOD(domelement, __construct)
 {
 
-       zval *id;
+       zval *id = getThis();
        xmlNodePtr nodep = NULL, oldnode = NULL;
        dom_object *intern;
        char *name, *value = NULL, *uri = NULL;
@@ -163,14 +163,10 @@ PHP_METHOD(domelement, __construct)
        size_t name_len, value_len = 0, uri_len = 0;
        int name_valid;
        xmlNsPtr nsptr = NULL;
-       zend_error_handling error_handling;
 
-       zend_replace_error_handling(EH_THROW, dom_domexception_class_entry, &error_handling);
-       if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os|s!s", &id, dom_element_class_entry, &name, &name_len, &value, &value_len, &uri, &uri_len) == FAILURE) {
-               zend_restore_error_handling(&error_handling);
+       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s|s!s", &name, &name_len, &value, &value_len, &uri, &uri_len) == FAILURE) {
                return;
        }
-       zend_restore_error_handling(&error_handling);
 
        name_valid = xmlValidateName((xmlChar *) name, 0);
        if (name_valid != 0) {
index 20eff5c72d72394008e7cb49b76b4aa68fa5c7d8..a3e3eaea0fc9372792829aa5cc0ba17c99cc66f3 100644 (file)
@@ -48,22 +48,17 @@ const zend_function_entry php_dom_entityreference_class_functions[] = {
 /* {{{ proto void DOMEntityReference::__construct(string name); */
 PHP_METHOD(domentityreference, __construct)
 {
-       zval *id;
+       zval *id = getThis();
        xmlNode *node;
        xmlNodePtr oldnode = NULL;
        dom_object *intern;
        char *name;
        size_t name_len, name_valid;
-       zend_error_handling error_handling;
 
-       zend_replace_error_handling(EH_THROW, dom_domexception_class_entry, &error_handling);
-       if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &id, dom_entityreference_class_entry, &name, &name_len) == FAILURE) {
-               zend_restore_error_handling(&error_handling);
+       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) {
                return;
        }
 
-       zend_restore_error_handling(&error_handling);
-
        name_valid = xmlValidateName((xmlChar *) name, 0);
        if (name_valid != 0) {
                php_dom_throw_error(INVALID_CHARACTER_ERR, 1);
index 7b18096fab84778c144e19ef7b02471e7ba8c8ba..38b934d0112d4c9d103e4233422eabca9fe8472b 100644 (file)
@@ -50,22 +50,17 @@ const zend_function_entry php_dom_processinginstruction_class_functions[] = {
 /* {{{ proto void DOMProcessingInstruction::__construct(string name, [string value]); */
 PHP_METHOD(domprocessinginstruction, __construct)
 {
-       zval *id;
+       zval *id = getThis();
        xmlNodePtr nodep = NULL, oldnode = NULL;
        dom_object *intern;
        char *name, *value = NULL;
        size_t name_len, value_len;
        int name_valid;
-       zend_error_handling error_handling;
 
-       zend_replace_error_handling(EH_THROW, dom_domexception_class_entry, &error_handling);
-       if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os|s", &id, dom_processinginstruction_class_entry, &name, &name_len, &value, &value_len) == FAILURE) {
-               zend_restore_error_handling(&error_handling);
+       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s|s", &name, &name_len, &value, &value_len) == FAILURE) {
                return;
        }
 
-       zend_restore_error_handling(&error_handling);
-
        name_valid = xmlValidateName((xmlChar *) name, 0);
        if (name_valid != 0) {
                php_dom_throw_error(INVALID_CHARACTER_ERR, 1);
index 08734ca473c22b4425840cee0008dc8bdeda16fb..53780c3321b8764f456f743a49cccf045a92e682 100644 (file)
@@ -7,11 +7,11 @@ Josh Sweeney <jsweeney@alt-invest.net>
 <?php require_once('skipif.inc'); ?>
 --FILE--
 <?php
-$attr = new DOMAttr();
+try {
+    $attr = new DOMAttr();
+} catch (TypeException $e) {
+    echo $e->getMessage(), "\n";
+}
 ?>
 --EXPECTF--
-Fatal error: Uncaught exception 'DOMException' with message 'DOMAttr::__construct() expects at least 1 parameter, 0 given' in %s:%d
-Stack trace:
-#0 %s(%d): DOMAttr->__construct()
-#1 {main}
-  thrown in %s on line %d
+DOMAttr::__construct() expects at least 1 parameter, 0 given
index 4db2130ba8e650c84d7ecd9cabf00e8b94f31403..2be1e5204f6d55ee0643b5f02c8d0e7e7c963dad 100644 (file)
@@ -7,15 +7,11 @@ Nic Rosental nicrosental@gmail.com
 <?php require_once('skipif.inc'); ?>
 --FILE--
 <?php
-       try 
-       {
+       try {
            $section = new DOMCDataSection();
-               
-       } 
-       catch (Exception $e) 
-       {
+       } catch (TypeException $e) {
            echo $e->getMessage();
        }
 ?>
 --EXPECT--
-DOMCdataSection::__construct() expects exactly 1 parameter, 0 given
\ No newline at end of file
+DOMCdataSection::__construct() expects exactly 1 parameter, 0 given
index 89142fe6f6b563e2ecb872c977a0f1b545b2319b..e2f0b19a72c20ade1e2d043c2f5dfd4ba50832ee 100644 (file)
@@ -7,11 +7,11 @@ Eric Lee Stewart <ericleestewart@gmail.com>
 <?php require_once('skipif.inc'); ?>
 --FILE--
 <?php
-$comment = new DOMComment("comment1", "comment2");
+try {
+    $comment = new DOMComment("comment1", "comment2");
+} catch (TypeException $e) {
+    echo $e->getMessage(), "\n";
+}
 ?>
 --EXPECTF--
-Fatal error: Uncaught exception 'DOMException' with message 'DOMComment::__construct() expects at most 1 parameter, 2 given' in %s:%d
-Stack trace:
-#0 %s(%d): DOMComment->__construct('comment1', 'comment2')
-#1 {main}
-  thrown in %s on line %d
\ No newline at end of file
+DOMComment::__construct() expects at most 1 parameter, 2 given
index 91173c4b7c2f6963d1047c2ef30799176ebb1859..d9376a325180008027dece303360cd3ebdd2f5b6 100644 (file)
@@ -7,11 +7,11 @@ Eric Lee Stewart <ericleestewart@gmail.com>
 <?php require_once('skipif.inc'); ?>
 --FILE--
 <?php
-$fragment = new DOMDocumentFragment("root");
+try {
+    $fragment = new DOMDocumentFragment("root");
+} catch (TypeException $e) {
+    echo $e->getMessage(), "\n";
+}
 ?>
 --EXPECTF--
-Fatal error: Uncaught exception 'DOMException' with message 'DOMDocumentFragment::__construct() expects exactly 0 parameters, 1 given' in %s:%d
-Stack trace:
-#0 %s(%d): DOMDocumentFragment->__construct('root')
-#1 {main}
-  thrown in %s on line %d
\ No newline at end of file
+DOMDocumentFragment::__construct() expects exactly 0 parameters, 1 given
index 50e8f89f5444b4f81d5c5e932c0687ba3437fd81..f857163ce196eba679066cebc4334510533aa2c0 100644 (file)
@@ -65,20 +65,16 @@ const zend_function_entry php_dom_text_class_functions[] = {
 PHP_METHOD(domtext, __construct)
 {
 
-       zval *id;
+       zval *id = getThis();
        xmlNodePtr nodep = NULL, oldnode = NULL;
        dom_object *intern;
        char *value = NULL;
        size_t value_len;
-       zend_error_handling error_handling;
 
-       zend_replace_error_handling(EH_THROW, dom_domexception_class_entry, &error_handling);
-       if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|s", &id, dom_text_class_entry, &value, &value_len) == FAILURE) {
-               zend_restore_error_handling(&error_handling);
+       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "|s", &value, &value_len) == FAILURE) {
                return;
        }
 
-       zend_restore_error_handling(&error_handling);
        nodep = xmlNewText((xmlChar *) value);
 
        if (!nodep) {
index 1fb6574695a468d60f0c05876ee3068a7efd48ee..58155c1aa9d2623a814b041f855ec6721894c87a 100644 (file)
@@ -253,20 +253,16 @@ static void dom_xpath_ext_function_object_php(xmlXPathParserContextPtr ctxt, int
 /* {{{ proto void DOMXPath::__construct(DOMDocument doc) U */
 PHP_METHOD(domxpath, __construct)
 {
-       zval *id, *doc;
+       zval *id = getThis(), *doc;
        xmlDocPtr docp = NULL;
        dom_object *docobj;
        dom_xpath_object *intern;
        xmlXPathContextPtr ctx, oldctx;
-       zend_error_handling error_handling;
 
-       zend_replace_error_handling(EH_THROW, dom_domexception_class_entry, &error_handling);
-       if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "OO", &id, dom_xpath_class_entry, &doc, dom_document_class_entry) == FAILURE) {
-               zend_restore_error_handling(&error_handling);
+       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "O", &doc, dom_document_class_entry) == FAILURE) {
                return;
        }
 
-       zend_restore_error_handling(&error_handling);
        DOM_GET_OBJ(docp, doc, xmlDocPtr, docobj);
 
        ctx = xmlXPathNewContext(docp);
index 975a0db4c1630282f4eb0f0a3a6f7d97c5c19d3b..c4745f92febb182d467547228d3ea1aaf1fb1f5e 100644 (file)
@@ -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);
index 838faf5b7d302b80c731211c674fe69673f95feb..4b622c65ae92a7388ae76c070e50b9b583970ee2 100644 (file)
@@ -7,11 +7,11 @@ if (!class_exists('finfo'))
 --FILE--
 <?php
 
-$finfo = new finfo(1, '', false);
-var_dump($finfo);
+try {
+    $finfo = new finfo(1, '', false);
+    var_dump($finfo);
+} catch (TypeException $e) {
+    echo $e->getMessage(), "\n";
+}
 --EXPECTF--
-Fatal error: Uncaught exception 'Exception' with message 'finfo::finfo() expects at most 2 parameters, 3 given' in %sbug61173.php:3
-Stack trace:
-#0 %sbug61173.php(3): finfo->finfo(1, '', false)
-#1 {main}
-  thrown in %sbug61173.php on line 3
+finfo::finfo() expects at most 2 parameters, 3 given
index d02be60e3191cde67cff744f468fac7e11e59bf9..1f6f935247c4514eadf45243dbbab6c3386a3fb7 100644 (file)
@@ -20,7 +20,11 @@ var_dump( finfo_open( FILEINFO_MIME, $magicFile, 'extraArg' ) );
 var_dump( finfo_open( PHP_INT_MAX - 1, $magicFile ) );
 var_dump( finfo_open( 'foobar' ) );
 
-var_dump( new finfo('foobar') );
+try {
+    var_dump( new finfo('foobar') );
+} catch (TypeException $e) {
+    echo $e->getMessage(), "\n";
+}
 
 ?>
 ===DONE===
@@ -45,9 +49,5 @@ resource(6) of type (file_info)
 
 Warning: finfo_open() expects parameter 1 to be integer, string given in %sfinfo_open_error.php on line 16
 bool(false)
-
-Fatal error: Uncaught exception 'Exception' with message 'finfo::finfo() expects parameter 1 to be integer, string given' in %sfinfo_open_error.php:18
-Stack trace:
-#0 %sfinfo_open_error.php(18): finfo->finfo('foobar')
-#1 {main}
-  thrown in %sfinfo_open_error.php on line 18
+finfo::finfo() expects parameter 1 to be integer, string given
+===DONE===
index b43f8212d0ed9f8ee3dad2cbca0f76c2729739ac..4dee58df2ed2675764a096b10fecd7512984edf1 100644 (file)
@@ -32,14 +32,13 @@ static inline RuleBasedBreakIterator *fetch_rbbi(BreakIterator_object *bio) {
 
 static void _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
 {
-       zval            *object         = getThis();
        char            *rules;
        size_t          rules_len;
        zend_bool       compiled        = 0;
        UErrorCode      status          = U_ZERO_ERROR;
        intl_error_reset(NULL);
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|b",
+       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s|b",
                        &rules, &rules_len, &compiled) == FAILURE) {
                intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
                        "rbbi_create_instance: bad arguments", 0);
index d9572a0668c021a72c785c4a347c1f8e1d220c92..d970cab595b4878c4a2f1816de3327b010076f17 100644 (file)
@@ -38,7 +38,8 @@ static inline GregorianCalendar *fetch_greg(Calendar_object *co) {
        return (GregorianCalendar*)co->ucal;
 }
 
-static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
+static void _php_intlgregcal_constructor_body(
+    INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor)
 {
        zval            *tz_object      = NULL;
        zval            args_a[6] = {0},
@@ -48,6 +49,7 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
        zend_long               largs[6];
        UErrorCode      status          = U_ZERO_ERROR;
        int                     variant;
+  int zpp_flags = is_constructor ? ZEND_PARSE_PARAMS_THROW : 0;
        intl_error_reset(NULL);
 
        // parameter number validation / variant determination
@@ -71,7 +73,7 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
 
        // argument parsing
        if (variant <= 2) {
-               if (zend_parse_parameters(MIN(ZEND_NUM_ARGS(), 2),
+               if (zend_parse_parameters_ex(zpp_flags, MIN(ZEND_NUM_ARGS(), 2),
                                "|z!s!", &tz_object, &locale, &locale_len) == FAILURE) {
                        intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
                                "intlgregcal_create_instance: bad arguments", 0);
@@ -79,7 +81,7 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
                        return;
                }
        }
-       if (variant > 2 && zend_parse_parameters(ZEND_NUM_ARGS(),
+       if (variant > 2 && zend_parse_parameters_ex(zpp_flags, ZEND_NUM_ARGS(),
                        "lll|lll", &largs[0], &largs[1], &largs[2], &largs[3], &largs[4],
                        &largs[5]) == FAILURE) {
                intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
@@ -181,7 +183,7 @@ U_CFUNC PHP_FUNCTION(intlgregcal_create_instance)
        object_init_ex(return_value, GregorianCalendar_ce_ptr);
        ZVAL_COPY_VALUE(&orig, return_value);
 
-       _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+       _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
 
        if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
                zval_dtor(&orig);
@@ -195,8 +197,7 @@ U_CFUNC PHP_METHOD(IntlGregorianCalendar, __construct)
 
        zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
        return_value = getThis();
-       //changes this to IS_NULL (without first destroying) if there's an error
-       _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+       _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
        if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
                if (!EG(exception)) {
                        zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
index c6bc3fd209262a4502f12e9db8c5eef516ddd42f..b6ad4502db0dd620fc520d0a9388d8fb7bbf6bb3 100644 (file)
 #include "intl_data.h"
 
 /* {{{ */
-static void collator_ctor(INTERNAL_FUNCTION_PARAMETERS)
+static void collator_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor)
 {
        const char*      locale;
        size_t           locale_len = 0;
        zval*            object;
        Collator_object* co;
+       int zpp_flags = is_constructor ? ZEND_PARSE_PARAMS_THROW : 0;
 
        intl_error_reset( NULL );
        object = return_value;
        /* Parse parameters. */
-       if( zend_parse_parameters( ZEND_NUM_ARGS(), "s",
+       if( zend_parse_parameters_ex( zpp_flags, ZEND_NUM_ARGS(), "s",
                &locale, &locale_len ) == FAILURE )
        {
                intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
@@ -63,7 +64,7 @@ static void collator_ctor(INTERNAL_FUNCTION_PARAMETERS)
 PHP_FUNCTION( collator_create )
 {
        object_init_ex( return_value, Collator_ce_ptr );
-       collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+       collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
 }
 /* }}} */
 
@@ -76,7 +77,7 @@ PHP_METHOD( Collator, __construct )
 
        zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
        return_value = getThis();
-       collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+       collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
        if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
                if (!EG(exception)) {
                        zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
index fd3aced34db970390badbcb0b2ece35438f567b7..621d0ead1299c6869e05bbccbb6953dff21212cf 100644 (file)
@@ -557,19 +557,10 @@ static PHP_METHOD(UConverter, __construct) {
        size_t src_len = sizeof("utf-8") - 1;
        char *dest = src;
        size_t dest_len = src_len;
-       zend_error_handling zeh;
-       int rv;
 
        intl_error_reset(NULL);
 
-       zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &zeh);
-       rv = zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s!",
-                                 &dest, &dest_len, &src, &src_len);
-       zend_restore_error_handling(&zeh);
-
-       if (rv == FAILURE) {
-               intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
-                       "UConverter::__construct(): bad arguments", 0);
+       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "|s!s!", &dest, &dest_len, &src, &src_len) == FAILURE) {
                return;
        }
 
index b7ad7b5126451eb2564d3681ed11af78534844ca..afc182131d6e7a486c4c41e57fea2cc4f105ae96 100644 (file)
@@ -37,7 +37,7 @@ extern "C" {
 #include "zend_exceptions.h"
 
 /* {{{ */
-static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
+static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor)
 {
        zval            *object;
 
@@ -58,11 +58,12 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
     UChar*      svalue                 = NULL;         /* UTF-16 pattern_str */
     int32_t     slength                        = 0;
        IntlDateFormatter_object* dfo;
+  int zpp_flags = is_constructor ? ZEND_PARSE_PARAMS_THROW : 0;
 
        intl_error_reset(NULL);
        object = return_value;
        /* Parse parameters. */
-    if (zend_parse_parameters(ZEND_NUM_ARGS(), "sll|zzs",
+    if (zend_parse_parameters_ex(zpp_flags, ZEND_NUM_ARGS(), "sll|zzs",
                        &locale_str, &locale_len, &date_type, &time_type, &timezone_zv,
                        &calendar_zv, &pattern_str, &pattern_str_len) == FAILURE) {
                intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: "
@@ -176,7 +177,7 @@ error:
 U_CFUNC PHP_FUNCTION( datefmt_create )
 {
     object_init_ex( return_value, IntlDateFormatter_ce_ptr );
-       datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+       datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
        if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
                RETURN_NULL();
        }
@@ -194,7 +195,7 @@ U_CFUNC PHP_METHOD( IntlDateFormatter, __construct )
        /* return_value param is being changed, therefore we will always return
         * NULL here */
        return_value = getThis();
-       datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+       datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
        if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
                if (!EG(exception)) {
                        zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
index 5d5a139688a522b323f8771de379db0435c4fa0a..5b7e6340539d5a0a591756aaccdd257927775818 100644 (file)
@@ -25,7 +25,7 @@
 #include "intl_convert.h"
 
 /* {{{ */
-static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
+static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor)
 {
        const char* locale;
        char*       pattern = NULL;
@@ -33,10 +33,11 @@ static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
        zend_long   style;
        UChar*      spattern     = NULL;
        int32_t     spattern_len = 0;
+       int         zpp_flags = is_constructor ? ZEND_PARSE_PARAMS_THROW : 0;
        FORMATTER_METHOD_INIT_VARS;
 
        /* Parse parameters. */
-       if( zend_parse_parameters( ZEND_NUM_ARGS(), "sl|s",
+       if( zend_parse_parameters_ex( zpp_flags, ZEND_NUM_ARGS(), "sl|s",
                &locale, &locale_len, &style, &pattern, &pattern_len ) == FAILURE )
        {
                intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
@@ -78,7 +79,7 @@ static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
 PHP_FUNCTION( numfmt_create )
 {
        object_init_ex( return_value, NumberFormatter_ce_ptr );
-       numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+       numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
        if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
                RETURN_NULL();
        }
@@ -94,7 +95,7 @@ PHP_METHOD( NumberFormatter, __construct )
 
        zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
        return_value = getThis();
-       numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+       numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
        if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
                if (!EG(exception)) {
                        zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
index a946705a764c5efda5832990742945cca34eca96..adbdd5afb8cf6d407e82d92c707f350ad4a8fb25 100644 (file)
@@ -101,7 +101,7 @@ void intl_error_reset( intl_error* err )
 /* {{{ void intl_error_set_custom_msg( intl_error* err, char* msg, int copyMsg )
  * Set last error message to msg copying it if needed.
  */
-void intl_error_set_custom_msg( intl_error* err, char* msg, int copyMsg )
+void intl_error_set_custom_msg( intl_error* err, const char* msg, int copyMsg )
 {
        if( !msg )
                return;
@@ -122,7 +122,7 @@ void intl_error_set_custom_msg( intl_error* err, char* msg, int copyMsg )
        err->free_custom_error_message = copyMsg;
 
        /* Set user's error text message */
-       err->custom_error_message = copyMsg ? estrdup( msg ) : msg;
+       err->custom_error_message = copyMsg ? estrdup( msg ) : (char *) msg;
 }
 /* }}} */
 
@@ -180,7 +180,7 @@ UErrorCode intl_error_get_code( intl_error* err )
 /* {{{ void intl_error_set( intl_error* err, UErrorCode code, char* msg, int copyMsg )
  * Set error code and message.
  */
-void intl_error_set( intl_error* err, UErrorCode code, char* msg, int copyMsg )
+void intl_error_set( intl_error* err, UErrorCode code, const char* msg, int copyMsg )
 {
        intl_error_set_code( err, code );
        intl_error_set_custom_msg( err, msg, copyMsg );
@@ -190,7 +190,7 @@ void intl_error_set( intl_error* err, UErrorCode code, char* msg, int copyMsg )
 /* {{{ void intl_errors_set( intl_error* err, UErrorCode code, char* msg, int copyMsg )
  * Set error code and message.
  */
-void intl_errors_set( intl_error* err, UErrorCode code, char* msg, int copyMsg )
+void intl_errors_set( intl_error* err, UErrorCode code, const char* msg, int copyMsg )
 {
        intl_errors_set_code( err, code );
        intl_errors_set_custom_msg( err, msg, copyMsg );
@@ -210,7 +210,7 @@ void intl_errors_reset( intl_error* err )
 
 /* {{{ void intl_errors_set_custom_msg( intl_error* err, char* msg, int copyMsg )
  */
-void intl_errors_set_custom_msg( intl_error* err, char* msg, int copyMsg )
+void intl_errors_set_custom_msg( intl_error* err, const char* msg, int copyMsg )
 {
        if(err) {
                intl_error_set_custom_msg( err, msg, copyMsg );
index 02d62f0299666ba7c7ff0ea6f4b96254c87d2392..b65bb2abee8add55bcf16940d38c6174568ec518 100644 (file)
@@ -35,16 +35,16 @@ intl_error* intl_error_create( void );
 void        intl_error_init( intl_error* err );
 void        intl_error_reset( intl_error* err );
 void        intl_error_set_code( intl_error* err, UErrorCode err_code );
-void        intl_error_set_custom_msg( intl_error* err, char* msg, int copyMsg );
-void        intl_error_set( intl_error* err, UErrorCode code, char* msg, int copyMsg );
+void        intl_error_set_custom_msg( intl_error* err, const char* msg, int copyMsg );
+void        intl_error_set( intl_error* err, UErrorCode code, const char* msg, int copyMsg );
 UErrorCode  intl_error_get_code( intl_error* err );
 zend_string* intl_error_get_message( intl_error* err );
 
 // Wrappers to synchonize object's and global error structures.
 void        intl_errors_reset( intl_error* err );
-void        intl_errors_set_custom_msg( intl_error* err, char* msg, int copyMsg );
+void        intl_errors_set_custom_msg( intl_error* err, const char* msg, int copyMsg );
 void        intl_errors_set_code( intl_error* err, UErrorCode err_code );
-void        intl_errors_set( intl_error* err, UErrorCode code, char* msg, int copyMsg );
+void        intl_errors_set( intl_error* err, UErrorCode code, const char* msg, int copyMsg );
 
 // Other error helpers
 smart_str      intl_parse_error_to_string( UParseError* pe );
index 15d6ef83214250c7b1faa596f1f5d5bd2151498e..2675aca5b8e66de8679e8c594d75ef03fcfa8ab0 100644 (file)
@@ -26,7 +26,7 @@
 #include "intl_convert.h"
 
 /* {{{ */
-static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
+static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor)
 {
        const char* locale;
        char*       pattern;
@@ -35,11 +35,12 @@ static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
        int         spattern_len = 0;
        zval*       object;
        MessageFormatter_object* mfo;
+       int zpp_flags = is_constructor ? ZEND_PARSE_PARAMS_THROW : 0;
        intl_error_reset( NULL );
 
        object = return_value;
        /* Parse parameters. */
-       if( zend_parse_parameters( ZEND_NUM_ARGS(), "ss",
+       if( zend_parse_parameters_ex( zpp_flags, ZEND_NUM_ARGS(), "ss",
                &locale, &locale_len, &pattern, &pattern_len ) == FAILURE )
        {
                intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
@@ -96,7 +97,7 @@ static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
 PHP_FUNCTION( msgfmt_create )
 {
        object_init_ex( return_value, MessageFormatter_ce_ptr );
-       msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+       msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
        if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
                RETURN_NULL();
        }
@@ -112,7 +113,7 @@ PHP_METHOD( MessageFormatter, __construct )
 
        zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
        return_value = getThis();
-       msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+       msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
        if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
                if (!EG(exception)) {
                        zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
index d8d1aa0d9c5d8a64654b0b0866da479ff3ca7ddb..a42556f746c9f35f858d4a6e7ecb1ae28ae5a463 100644 (file)
@@ -75,20 +75,21 @@ static zend_object *ResourceBundle_object_create( zend_class_entry *ce )
 /* }}} */
 
 /* {{{ ResourceBundle_ctor */
-static void resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS)
+static void resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor)
 {
        const char *bundlename;
        size_t          bundlename_len = 0;
        const char *locale;
        size_t          locale_len = 0;
        zend_bool       fallback = 1;
+       int         zpp_flags = is_constructor ? ZEND_PARSE_PARAMS_THROW : 0;
 
        zval                  *object = return_value;
        ResourceBundle_object *rb = Z_INTL_RESOURCEBUNDLE_P( object );
 
        intl_error_reset( NULL );
 
-       if( zend_parse_parameters( ZEND_NUM_ARGS(), "s!s!|b",
+       if( zend_parse_parameters_ex( zpp_flags, ZEND_NUM_ARGS(), "s!s!|b",
                &locale, &locale_len, &bundlename, &bundlename_len, &fallback ) == FAILURE )
        {
                intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
@@ -144,7 +145,7 @@ PHP_METHOD( ResourceBundle, __construct )
 
        zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
        return_value = getThis();
-       resourcebundle_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+       resourcebundle_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
        if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
                if (!EG(exception)) {
                        zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
@@ -160,7 +161,7 @@ proto ResourceBundle resourcebundle_create( string $locale [, string $bundlename
 PHP_FUNCTION( resourcebundle_create )
 {
        object_init_ex( return_value, ResourceBundle_ce_ptr );
-       resourcebundle_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
+       resourcebundle_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
        if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
                RETURN_NULL();
        }
index d206bc81cb1d55de5d48e5bccdbb5a7cb8e69d9e..865f600dfc3e856ab46a1f61a1269b324b3a57b2 100644 (file)
@@ -32,13 +32,12 @@ PHP_METHOD(Spoofchecker, __construct)
        zend_error_handling error_handling;
        SPOOFCHECKER_METHOD_INIT_VARS;
 
-       zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
-
-       if (zend_parse_parameters_none() == FAILURE) {
-               zend_restore_error_handling(&error_handling);
+       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "") == FAILURE) {
                return;
        }
 
+       zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
+
        SPOOFCHECKER_METHOD_FETCH_OBJECT_NO_CHECK;
 
        co->uspoof = uspoof_open(SPOOFCHECKER_ERROR_CODE_P(co));
index bea65667faa1136e2bfc237bbb7e22d62f03c9da..7e67fd7403361e8b8fa4ce893084a1952989e2c1 100644 (file)
@@ -19,17 +19,17 @@ try {
 }
 try {
        var_dump(new IntlRuleBasedBreakIterator());
-} catch (IntlException $e) {
+} catch (TypeException $e) {
        print_exception($e);
 }
 try {
        var_dump(new IntlRuleBasedBreakIterator(1,2,3));
-} catch (IntlException $e) {
+} catch (TypeException $e) {
        print_exception($e);
 }
 try {
        var_dump(new IntlRuleBasedBreakIterator('[\p{Letter}\uFFFD]+;[:number:]+;', array()));
-} catch (IntlException $e) {
+} catch (TypeException $e) {
        print_exception($e);
 }
 try {
index f61cb14878a25dc25dd3a06638f323302a7f0798..f7761173dd738c4eae74e9e081d90e3d737c1f14 100644 (file)
@@ -12,7 +12,8 @@ function err($fmt) {
 }
 
 function print_exception($e) {
-       echo "\nException: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n";
+       echo "\n" . get_class($e) . ": " . $e->getMessage()
+       . " in " . $e->getFile() . " on line " . $e->getLine() . "\n";
 }
 
 function crt($t, $l, $s) {
@@ -20,7 +21,7 @@ function crt($t, $l, $s) {
                case $t == "O":
                        try {
                                return new NumberFormatter($l, $s);
-                       } catch (IntlException $e) {
+                       } catch (BaseException $e) {
                                print_exception($e);
                                return null;
                        }
@@ -44,7 +45,7 @@ $args = array(
 
 try {
        $fmt = new NumberFormatter();
-} catch (IntlException $e) {
+} catch (TypeException $e) {
        print_exception($e);
        $fmt = null;
 }
@@ -65,7 +66,7 @@ foreach($args as $arg) {
 
 ?>
 --EXPECTF--
-Exception: NumberFormatter::__construct() expects at least 2 parameters, 0 given in %s on line %d
+TypeException: NumberFormatter::__construct() expects at least 2 parameters, 0 given in %s on line %d
 'numfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
 
 Warning: numfmt_create() expects at least 2 parameters, 0 given in %s on line %d
@@ -74,12 +75,12 @@ Warning: numfmt_create() expects at least 2 parameters, 0 given in %s on line %d
 Warning: NumberFormatter::create() expects at least 2 parameters, 0 given in %s on line %d
 'numfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
 
-Exception: Constructor failed in %sformatter_fail.php on line %d
+IntlException: Constructor failed in %sformatter_fail.php on line %d
 'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR'
 'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR'
 'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR'
 
-Exception: NumberFormatter::__construct() expects parameter 1 to be string, array given in %s on line %d
+TypeException: NumberFormatter::__construct() expects parameter 1 to be string, array given in %s on line %d
 'numfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
 
 Warning: NumberFormatter::create() expects parameter 1 to be string, array given in %s on line %d
@@ -88,12 +89,12 @@ Warning: NumberFormatter::create() expects parameter 1 to be string, array given
 Warning: numfmt_create() expects parameter 1 to be string, array given in %s on line %d
 'numfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
 
-Exception: Constructor failed in %sformatter_fail.php on line %d
+IntlException: Constructor failed in %sformatter_fail.php on line %d
 'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR'
 'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR'
 'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR'
 
-Exception: Constructor failed in %sformatter_fail.php on line %d
+IntlException: Constructor failed in %sformatter_fail.php on line %d
 'numfmt_create: number formatter creation failed: U_MEMORY_ALLOCATION_ERROR'
 'numfmt_create: number formatter creation failed: U_MEMORY_ALLOCATION_ERROR'
 'numfmt_create: number formatter creation failed: U_MEMORY_ALLOCATION_ERROR'
index d81809793eb3627d4027e750aa182144eec06dff..7383bdee88675f3d8c6d4aeb281a5d7b9c593f16 100644 (file)
@@ -22,7 +22,7 @@ try {
 }
 try {
        var_dump(new IntlGregorianCalendar(1,2,3,4,NULL,array()));
-} catch (IntlException $e) {
+} catch (TypeException $e) {
        print_exception($e);
 }
 --EXPECTF--
index 7c76598c0d4198672fc33a441bc4873d4339be33..d7ca83d4424c5f68d9be9f79c2cb9bdd90b10a43 100644 (file)
@@ -13,7 +13,8 @@ function err($fmt) {
 }
 
 function print_exception($e) {
-       echo "\nException: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n";
+       echo "\n" . get_class($e) . ": " . $e->getMessage()
+       . " in " . $e->getFile() . " on line " . $e->getLine() . "\n";
 }
 
 function crt($t, $l, $s) {
@@ -21,7 +22,7 @@ function crt($t, $l, $s) {
                case $t == "O":
                        try {
                                return new MessageFormatter($l, $s);
-                       } catch (IntlException $e) {
+                       } catch (BaseException $e) {
                                print_exception($e);
                                return null;
                        }
@@ -46,7 +47,7 @@ $args = array(
 
 try {
        $fmt = new MessageFormatter();
-} catch (IntlException $e) {
+} catch (TypeException $e) {
        print_exception($e);
        $fmt = null;
 }
@@ -57,7 +58,7 @@ $fmt = MessageFormatter::create();
 err($fmt);
 try {
        $fmt = new MessageFormatter('en');
-} catch (IntlException $e) {
+} catch (TypeException $e) {
        print_exception($e);
        $fmt = null;
 }
@@ -78,7 +79,7 @@ foreach($args as $arg) {
 
 ?>
 --EXPECTF--
-Exception: MessageFormatter::__construct() expects exactly 2 parameters, 0 given in %s on line %d
+TypeException: MessageFormatter::__construct() expects exactly 2 parameters, 0 given in %s on line %d
 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
 
 Warning: msgfmt_create() expects exactly 2 parameters, 0 given in %s on line %d
@@ -87,7 +88,7 @@ Warning: msgfmt_create() expects exactly 2 parameters, 0 given in %s on line %d
 Warning: MessageFormatter::create() expects exactly 2 parameters, 0 given in %s on line %d
 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
 
-Exception: MessageFormatter::__construct() expects exactly 2 parameters, 1 given in %s on line %d
+TypeException: MessageFormatter::__construct() expects exactly 2 parameters, 1 given in %s on line %d
 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
 
 Warning: msgfmt_create() expects exactly 2 parameters, 1 given in %s on line %d
@@ -96,17 +97,17 @@ Warning: msgfmt_create() expects exactly 2 parameters, 1 given in %s on line %d
 Warning: MessageFormatter::create() expects exactly 2 parameters, 1 given in %s on line %d
 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
 
-Exception: Constructor failed in %smsgfmt_fail2.php on line %d
+IntlException: Constructor failed in %smsgfmt_fail2.php on line %d
 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
 
-Exception: Constructor failed in %smsgfmt_fail2.php on line %d
+IntlException: Constructor failed in %smsgfmt_fail2.php on line %d
 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
 
-Exception: MessageFormatter::__construct() expects parameter 1 to be string, array given in %s on line %d
+TypeException: MessageFormatter::__construct() expects parameter 1 to be string, array given in %s on line %d
 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
 
 Warning: MessageFormatter::create() expects parameter 1 to be string, array given in %s on line %d
@@ -115,17 +116,17 @@ Warning: MessageFormatter::create() expects parameter 1 to be string, array give
 Warning: msgfmt_create() expects parameter 1 to be string, array given in %s on line %d
 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
 
-Exception: Constructor failed in %smsgfmt_fail2.php on line %d
+IntlException: Constructor failed in %smsgfmt_fail2.php on line %d
 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
 
-Exception: Constructor failed in %smsgfmt_fail2.php on line %d
+IntlException: Constructor failed in %smsgfmt_fail2.php on line %d
 'msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES'
 'msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES'
 'msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES'
 
-Exception: Constructor failed in %smsgfmt_fail2.php on line %d
+IntlException: Constructor failed in %smsgfmt_fail2.php on line %d
 'msgfmt_create: error converting pattern to UTF-16: U_INVALID_CHAR_FOUND'
 'msgfmt_create: error converting pattern to UTF-16: U_INVALID_CHAR_FOUND'
 'msgfmt_create: error converting pattern to UTF-16: U_INVALID_CHAR_FOUND'
index 0ab99cf6339680862fc84e06f65ec1e6cbdb624d..6e34bfde68821f1bf8baab2a974c02b3eefa3cec 100644 (file)
@@ -13,7 +13,8 @@ function err($fmt) {
 }
 
 function print_exception($e) {
-       echo "\nException: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n";
+       echo "\n" . get_class($e) . ": " . $e->getMessage()
+       . " in " . $e->getFile() . " on line " . $e->getLine() . "\n";
 }
 
 function crt($t, $l, $s) {
@@ -21,7 +22,7 @@ function crt($t, $l, $s) {
                case $t == "O":
                        try {
                                return new MessageFormatter($l, $s);
-                       } catch (IntlException $e) {
+                       } catch (BaseException $e) {
                                print_exception($e);
                                return null;
                        }
@@ -46,7 +47,7 @@ $args = array(
 
 try {
        $fmt = new MessageFormatter();
-} catch (IntlException $e) {
+} catch (TypeException $e) {
        print_exception($e);
        $fmt = null;
 }
@@ -57,7 +58,7 @@ $fmt = MessageFormatter::create();
 err($fmt);
 try {
        $fmt = new MessageFormatter('en');
-} catch (IntlException $e) {
+} catch (TypeException $e) {
        print_exception($e);
        $fmt = null;
 }
@@ -78,7 +79,7 @@ foreach($args as $arg) {
 
 ?>
 --EXPECTF--
-Exception: MessageFormatter::__construct() expects exactly 2 parameters, 0 given in %s on line %d
+TypeException: MessageFormatter::__construct() expects exactly 2 parameters, 0 given in %s on line %d
 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
 
 Warning: msgfmt_create() expects exactly 2 parameters, 0 given in %s on line %d
@@ -87,7 +88,7 @@ Warning: msgfmt_create() expects exactly 2 parameters, 0 given in %s on line %d
 Warning: MessageFormatter::create() expects exactly 2 parameters, 0 given in %s on line %d
 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
 
-Exception: MessageFormatter::__construct() expects exactly 2 parameters, 1 given in %s on line %d
+TypeException: MessageFormatter::__construct() expects exactly 2 parameters, 1 given in %s on line %d
 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
 
 Warning: msgfmt_create() expects exactly 2 parameters, 1 given in %s on line %d
@@ -96,17 +97,17 @@ Warning: msgfmt_create() expects exactly 2 parameters, 1 given in %s on line %d
 Warning: MessageFormatter::create() expects exactly 2 parameters, 1 given in %s on line %d
 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
 
-Exception: Constructor failed in %smsgfmt_fail2.php on line %d
+IntlException: Constructor failed in %smsgfmt_fail2.php on line %d
 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
 
-Exception: Constructor failed in %smsgfmt_fail2.php on line %d
+IntlException: Constructor failed in %smsgfmt_fail2.php on line %d
 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
 
-Exception: MessageFormatter::__construct() expects parameter 1 to be string, array given in %s on line %d
+TypeException: MessageFormatter::__construct() expects parameter 1 to be string, array given in %s on line %d
 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
 
 Warning: MessageFormatter::create() expects parameter 1 to be string, array given in %s on line %d
@@ -115,17 +116,17 @@ Warning: MessageFormatter::create() expects parameter 1 to be string, array give
 Warning: msgfmt_create() expects parameter 1 to be string, array given in %s on line %d
 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
 
-Exception: Constructor failed in %smsgfmt_fail2.php on line %d
+IntlException: Constructor failed in %smsgfmt_fail2.php on line %d
 'msgfmt_create: message formatter creation failed: U_PATTERN_SYNTAX_ERROR'
 'msgfmt_create: message formatter creation failed: U_PATTERN_SYNTAX_ERROR'
 'msgfmt_create: message formatter creation failed: U_PATTERN_SYNTAX_ERROR'
 
-Exception: Constructor failed in %smsgfmt_fail2.php on line %d
+IntlException: Constructor failed in %smsgfmt_fail2.php on line %d
 'msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES'
 'msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES'
 'msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES'
 
-Exception: Constructor failed in %smsgfmt_fail2.php on line %d
+IntlException: Constructor failed in %smsgfmt_fail2.php on line %d
 'msgfmt_create: error converting pattern to UTF-16: U_INVALID_CHAR_FOUND'
 'msgfmt_create: error converting pattern to UTF-16: U_INVALID_CHAR_FOUND'
 'msgfmt_create: error converting pattern to UTF-16: U_INVALID_CHAR_FOUND'
index 47cba0edb947d9817eee589c60095cb9948050b5..f3df48540470e9b17cf586bba0f6700db71c3883 100644 (file)
@@ -210,13 +210,11 @@ static PHP_METHOD(PDO, dbh_constructor)
        int call_factory = 1;
        zend_error_handling zeh;
 
-       zend_replace_error_handling(EH_THROW, pdo_exception_ce, &zeh);
-       if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "s|s!s!a!", &data_source, &data_source_len,
+       if (FAILURE == zend_parse_parameters_throw(ZEND_NUM_ARGS(),
+                               "s|s!s!a!", &data_source, &data_source_len,
                                &username, &usernamelen, &password, &passwordlen, &options)) {
-               zend_restore_error_handling(&zeh);
                return;
        }
-       zend_restore_error_handling(&zeh);
 
        /* parse the data source name */
        colon = strchr(data_source, ':');
index 2a890c963d080fb33b0a5681d839ef2f753ada8e..f0048ff305b4b119bc1a596f09f3fcf0e3e46fe4 100644 (file)
@@ -31,7 +31,7 @@ MySQLPDOTest::skip();
            try {
                        if (NULL !== ($db = @new PDO()))
                                printf("[001] Too few parameters\n");
-               } catch (Exception $ex) {
+               } catch (TypeException $ex) {
                }
 
                print tryandcatch(2, '$db = new PDO(chr(0));');
index 5166958d24232a27af887843f5a0f98160931c7c..9a64f59fe20d691e374a29b72c2037e0e34d13a0 100644 (file)
@@ -70,7 +70,7 @@ MySQLPDOTest::skip();
                try {
                        if (NULL !== ($db = @new PDO($dsn, $user, $pass, 'wrong type')))
                                printf("[001] Expecting NULL got %s/%s\n", gettype($db), $db);
-               } catch (Exception $e) {
+               } catch (TypeException $e) {
                }
 
                if (!is_object($db = new PDO($dsn, $user, $pass, array())))
index 861f94e76375f6ba58e709ad4f26e77fd725057b..8ef5b0f7ed1a2a043d15ff133e05fe33bd6159e6 100644 (file)
@@ -1130,26 +1130,17 @@ PHP_METHOD(Phar, __construct)
        phar_archive_object *phar_obj;
        phar_archive_data   *phar_data;
        zval *zobj = getThis(), arg1, arg2;
-       zend_error_handling zeh;
-       int rv;
 
        phar_obj = (phar_archive_object*)((char*)Z_OBJ_P(zobj) - Z_OBJ_P(zobj)->handlers->offset);
 
        is_data = instanceof_function(Z_OBJCE_P(zobj), phar_ce_data);
 
        if (is_data) {
-               zend_replace_error_handling(EH_THROW, phar_ce_PharException, &zeh TSRMLS_CC);
-               rv = zend_parse_parameters(ZEND_NUM_ARGS(), "s|ls!l", &fname, &fname_len, &flags, &alias, &alias_len, &format);
-               zend_restore_error_handling(&zeh TSRMLS_CC);
-               if (rv == FAILURE) {
+               if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s|ls!l", &fname, &fname_len, &flags, &alias, &alias_len, &format) == FAILURE) {
                        return;
                }
        } else {
-               zend_replace_error_handling(EH_THROW, phar_ce_PharException, &zeh TSRMLS_CC);
-               rv = zend_parse_parameters(ZEND_NUM_ARGS(), "s|ls!", &fname, &fname_len, &flags, &alias, &alias_len);
-               zend_restore_error_handling(&zeh TSRMLS_CC);
-               if (rv == FAILURE) {
-                       /* Exception was thrown already */
+               if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s|ls!", &fname, &fname_len, &flags, &alias, &alias_len) == FAILURE) {
                        return;
                }
        }
@@ -4359,14 +4350,8 @@ PHP_METHOD(PharFileInfo, __construct)
        phar_entry_info *entry_info;
        phar_archive_data *phar_data;
        zval *zobj = getThis(), arg1;
-       zend_error_handling zeh;
-       int rv;
 
-       zend_replace_error_handling(EH_THROW, phar_ce_PharException, &zeh TSRMLS_CC);
-       rv = zend_parse_parameters(ZEND_NUM_ARGS(), "s", &fname, &fname_len);
-       zend_restore_error_handling(&zeh TSRMLS_CC);
-
-       if (rv == FAILURE) {
+       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &fname, &fname_len) == FAILURE) {
                return;
        }
 
index 7d5525b887ddcb534cdb558111c8d1ae9569ebc1..97faab427cb74c06569b9479132afa309ac17e7c 100644 (file)
@@ -18,7 +18,7 @@ Phar::loadPhar(array());
 Phar::canCompress('hi');
 try {
        $a = new Phar(array());
-} catch (PharException $e) {
+} catch (TypeException $e) {
        print_exception($e);
 }
 try {
index c27ff5b5547424fb4c09ffbe7a9403e3a797f731..2dd03b95174f77bec0bd8d2ab144cb7099695fd8 100644 (file)
@@ -5,17 +5,13 @@ Bug #60261 (phar dos null pointer)
 --FILE--
 <?php
 
-$nx = new Phar();
 try {
+    $nx = new Phar();
        $nx->getLinkTarget();
-} catch (Exception $e) {
+} catch (TypeException $e) {
        echo $e->getMessage(), "\n";
 }
 
 ?>
 --EXPECTF--
-Fatal error: Uncaught exception 'PharException' with message 'Phar::__construct() expects at least 1 parameter, 0 given' in %sbug60261.php:3
-Stack trace:
-#0 %sbug60261.php(3): Phar->__construct()
-#1 {main}
-  thrown in %sbug60261.php on line 3
+Phar::__construct() expects at least 1 parameter, 0 given
index df00161d55645c1a351441189701cd5dbbc9946a..abd0fac2e66f6cebc5ee6bc829ec0a31c234e8be 100644 (file)
@@ -17,7 +17,11 @@ echo $e->getMessage() . "\n";
 unlink($fname);
 }
 
+try {
 $a = new PharFileInfo(array());
+} catch (TypeException $e) {
+echo $e->getMessage() . "\n";
+}
 
 $a = new Phar($fname);
 $a['a'] = 'hi';
@@ -46,9 +50,8 @@ echo $e->getMessage() . "\n";
 <?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar'); ?>
 --EXPECTF--
 Cannot open phar file 'phar://%spharfileinfo_construct.phar/oops': internal corruption of phar "%spharfileinfo_construct.phar" (truncated entry)
-
-Fatal error: Uncaught exception 'PharException' with message 'PharFileInfo::__construct() expects parameter 1 to be string, array given' in %spharfileinfo_construct.php:13
-Stack trace:
-#0 %spharfileinfo_construct.php(13): PharFileInfo->__construct(Array)
-#1 {main}
-  thrown in %spharfileinfo_construct.php on line 13
+PharFileInfo::__construct() expects parameter 1 to be string, array given
+Cannot access phar file entry '%s' in archive '%s'
+Cannot call constructor twice
+'%s' is not a valid phar archive URL (must have at least phar://filename.phar)
+===DONE===
index b4dd978f080f5846709a1d879ffdc5a529667f59..da208f6c4b5fabb3afbf4e5147eaa26b9514ff95 100644 (file)
@@ -1572,13 +1572,11 @@ ZEND_METHOD(reflection_function, __construct)
        zval name;
        zval *object;
        zval *closure = NULL;
-       char *lcname;
+       char *lcname, *nsname;
        reflection_object *intern;
        zend_function *fptr;
        char *name_str;
        size_t name_len;
-       int rv;
-       zend_error_handling zeh;
 
        object = getThis();
        intern = Z_REFLECTION_P(object);
@@ -1590,31 +1588,26 @@ ZEND_METHOD(reflection_function, __construct)
                fptr = (zend_function*)zend_get_closure_method_def(closure);
                Z_ADDREF_P(closure);
        } else { 
-               zend_replace_error_handling(EH_THROW, reflection_exception_ptr, &zeh TSRMLS_CC);
-               rv = zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name_str, &name_len);
-               zend_restore_error_handling(&zeh TSRMLS_CC);
-               if (rv == SUCCESS) {
-                       char *nsname;
-                       lcname = zend_str_tolower_dup(name_str, name_len);
-       
-                       /* Ignore leading "\" */
-                       nsname = lcname;
-                       if (lcname[0] == '\\') {
-                               nsname = &lcname[1];
-                               name_len--;
-                       }
-       
-                       if ((fptr = zend_hash_str_find_ptr(EG(function_table), nsname, name_len)) == NULL) {
-                               efree(lcname);
-                               zend_throw_exception_ex(reflection_exception_ptr, 0,
-                                       "Function %s() does not exist", name_str);
-                               return;
-                       }
+               if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &name_str, &name_len) == FAILURE) {
+                       return;
+               }
+
+               lcname = zend_str_tolower_dup(name_str, name_len);
+
+               /* Ignore leading "\" */
+               nsname = lcname;
+               if (lcname[0] == '\\') {
+                       nsname = &lcname[1];
+                       name_len--;
+               }
+
+               if ((fptr = zend_hash_str_find_ptr(EG(function_table), nsname, name_len)) == NULL) {
                        efree(lcname);
-               } else {
-                       /* Exception has been thrown. */
+                       zend_throw_exception_ex(reflection_exception_ptr, 0,
+                               "Function %s() does not exist", name_str);
                        return;
                }
+               efree(lcname);
        }
 
        ZVAL_STR_COPY(&name, fptr->common.function_name);
@@ -2141,14 +2134,10 @@ ZEND_METHOD(reflection_parameter, __construct)
        zend_class_entry *ce = NULL;
        zend_bool is_closure = 0;
        zend_bool is_invoke = 0;
-       zend_error_handling zeh;
 
-       zend_replace_error_handling(EH_THROW, reflection_exception_ptr, &zeh TSRMLS_CC);
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &reference, &parameter) == FAILURE) {
-               zend_restore_error_handling(&zeh TSRMLS_CC);
+       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "zz", &reference, &parameter) == FAILURE) {
                return;
        }
-       zend_restore_error_handling(&zeh TSRMLS_CC);
 
        object = getThis();
        intern = Z_REFLECTION_P(object);
@@ -2729,17 +2718,13 @@ ZEND_METHOD(reflection_method, __construct)
        zval ztmp;
 
        if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "zs", &classname, &name_str, &name_len) == FAILURE) {
-               zend_error_handling zeh;
-               int rv;
-
-               zend_replace_error_handling(EH_THROW, reflection_exception_ptr, &zeh TSRMLS_CC);
-               rv = zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name_str, &name_len);
-               zend_restore_error_handling(&zeh TSRMLS_CC);
-               if (rv == FAILURE) {
+               if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &name_str, &name_len) == FAILURE) {
                        return;
                }
+
                if ((tmp = strstr(name_str, "::")) == NULL) {
-                       zend_throw_exception_ex(reflection_exception_ptr, 0, "Invalid method name %s", name_str);
+                       zend_throw_exception_ex(reflection_exception_ptr, 0,
+                               "Invalid method name %s", name_str);
                        return;
                }
                classname = &ztmp;
@@ -4833,14 +4818,7 @@ ZEND_METHOD(reflection_property, __construct)
        zend_property_info *property_info = NULL;
        property_reference *reference;
 
-       int rv;
-       zend_error_handling zeh;
-
-       zend_replace_error_handling(EH_THROW, reflection_exception_ptr, &zeh TSRMLS_CC);
-       rv = zend_parse_parameters(ZEND_NUM_ARGS(), "zs", &classname, &name_str, &name_len);
-       zend_restore_error_handling(&zeh TSRMLS_CC);
-
-       if (rv == FAILURE) {
+       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "zs", &classname, &name_str, &name_len) == FAILURE) {
                return;
        }
 
@@ -5239,15 +5217,9 @@ ZEND_METHOD(reflection_extension, __construct)
        zend_module_entry *module;
        char *name_str;
        size_t name_len;
-       int rv;
-       zend_error_handling zeh;
        ALLOCA_FLAG(use_heap)
 
-       zend_replace_error_handling(EH_THROW, reflection_exception_ptr, &zeh TSRMLS_CC);
-       rv = zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name_str, &name_len);
-       zend_restore_error_handling(&zeh TSRMLS_CC);
-
-       if (rv == FAILURE) {
+       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &name_str, &name_len) == FAILURE) {
                return;
        }
 
@@ -5614,14 +5586,8 @@ ZEND_METHOD(reflection_zend_extension, __construct)
        zend_extension *extension;
        char *name_str;
        size_t name_len;
-       int rv;
-       zend_error_handling zeh;
-
-       zend_replace_error_handling(EH_THROW, reflection_exception_ptr, &zeh TSRMLS_CC);
-       rv = zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name_str, &name_len);
-       zend_restore_error_handling(&zeh TSRMLS_CC);
 
-       if (rv == FAILURE) {
+       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &name_str, &name_len) == FAILURE) {
                return;
        }
 
index f731ab51cc7db59895a043e05dac73fc158d4a2a..235c2ad768ff3126c053a3f158a26532f07415c9 100644 (file)
@@ -7,22 +7,19 @@ Leon Luijkx <leon@phpgg.nl>
 <?php
 try {
        $obj = new ReflectionExtension();
-}
-catch(ReflectionException $re) {
+} catch (TypeException $re) {
        echo "Ok - ".$re->getMessage().PHP_EOL;
 }
 
 try {
        $obj = new ReflectionExtension('foo', 'bar');
-}
-catch(ReflectionException $re) {
+} catch (TypeException $re) {
        echo "Ok - ".$re->getMessage().PHP_EOL;
 }
 
 try {
        $obj = new ReflectionExtension([]);
-}
-catch(ReflectionException $re) {
+} catch (TypeException $re) {
        echo "Ok - ".$re->getMessage().PHP_EOL;
 }
 
index 90259ac9976a55f1dd1df85b4304217ad7209986..52db7c654d59ce3f1fc85aa7e1a1d2bccb9c0ae1 100644 (file)
@@ -9,31 +9,27 @@ Steve Seear <stevseea@php.net>
 try {
        $a = new ReflectionFunction(array(1, 2, 3));
        echo "exception not thrown.".PHP_EOL;
-}
-catch(ReflectionException $re) {
+} catch (TypeException $re) {
        echo "Ok - ".$re->getMessage().PHP_EOL;
 }
 try {
        $a = new ReflectionFunction('nonExistentFunction');
-} catch (Exception $e) {
+} catch (ReflectionException $e) {
        echo $e->getMessage().PHP_EOL;
 }
 try {
        $a = new ReflectionFunction();
-}
-catch(ReflectionException $re) {
+} catch (TypeException $re) {
        echo "Ok - ".$re->getMessage().PHP_EOL;
 }
 try {
        $a = new ReflectionFunction(1, 2);
-}
-catch(ReflectionException $re) {
+} catch (TypeException $re) {
        echo "Ok - ".$re->getMessage().PHP_EOL;
 }
 try {
        $a = new ReflectionFunction([]);
-}
-catch(ReflectionException $re) {
+} catch (TypeException $re) {
        echo "Ok - ".$re->getMessage().PHP_EOL;
 }
 
index 0b8228989c7bb3e41fa36c8bf3b3f84ea0329b29..b22a2acc6d724aec0d715474a90b305cb6d16bd0 100644 (file)
@@ -8,14 +8,12 @@ Steve Seear <stevseea@php.net>
 
 try {
        new ReflectionMethod();
-}
-catch(ReflectionException $re) {
+} catch (TypeException $re) {
        echo "Ok - ".$re->getMessage().PHP_EOL;
 }
 try {
        new ReflectionMethod('a', 'b', 'c');
-}
-catch(ReflectionException $re) {
+} catch (TypeException $re) {
        echo "Ok - ".$re->getMessage().PHP_EOL;
 }
 
index 85f80978254828d433286c0af8d8fc6a0dcc1fdc..3c521efc64b8e2a3cee630117d637f81c74f7785 100644 (file)
@@ -16,13 +16,13 @@ class TestClass
 try {
        echo "Too few arguments:\n";
        $methodInfo = new ReflectionMethod();
-} catch (ReflectionException $re) {
+} catch (TypeException $re) {
        echo "Ok - ".$re->getMessage().PHP_EOL;
 }
 try {
        echo "\nToo many arguments:\n";
        $methodInfo = new ReflectionMethod("TestClass", "foo", true);
-} catch (ReflectionException $re) {
+} catch (TypeException $re) {
        echo "Ok - ".$re->getMessage().PHP_EOL;
 }
 
@@ -45,7 +45,7 @@ try {
 try{
        //invalid 2nd param
        $methodInfo = new ReflectionMethod("TestClass", []);
-} catch (ReflectionException $re) {
+} catch (TypeException $re) {
        echo "Ok - ".$re->getMessage().PHP_EOL;
 }
 
index 1775dee5144197c3f3433b569b7c900f5577157c..a884162fd2a741030451f96da3ecaf8af5175aca 100644 (file)
@@ -25,7 +25,7 @@ class C {
 try {
        new ReflectionParameter(array ('A', 'b'));
 }
-catch(ReflectionException $e) {
+catch(TypeException $e) {
        printf( "Ok - %s\n", $e->getMessage());
 }
 
index d3910296b58bf54187937f07b1184e9fdd224975..ef051b53804a87ca7963e32df4a4f5d7834b54a5 100644 (file)
@@ -9,21 +9,18 @@ class C {
 
 try {
        new ReflectionProperty();
-}
-catch(ReflectionException $re) {
+} catch (TypeException $re) {
        echo "Ok - ".$re->getMessage().PHP_EOL;
 }
 try {
        new ReflectionProperty('C::p');
-}
-catch(ReflectionException $re) {
+} catch (TypeException $re) {
        echo "Ok - ".$re->getMessage().PHP_EOL;
 }
 
 try {
        new ReflectionProperty('C', 'p', 'x');
-}
-catch(ReflectionException $re) {
+} catch (TypeException $re) {
        echo "Ok - ".$re->getMessage().PHP_EOL;
 }
 
index ee21bbfbebf9116d10793acb399c30ccfcc122a6..abfeb158cd4c3f0df9600da296da432201b501a3 100644 (file)
@@ -2184,16 +2184,11 @@ SXE_METHOD(__construct)
        xmlDocPtr       docp;
        zend_long            options = 0;
        zend_bool       is_url = 0, isprefix = 0;
-       zend_error_handling error_handling;
 
-       zend_replace_error_handling(EH_THROW, NULL, &error_handling);
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|lbsb", &data, &data_len, &options, &is_url, &ns, &ns_len, &isprefix) == FAILURE) {
-               zend_restore_error_handling(&error_handling);
+       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s|lbsb", &data, &data_len, &options, &is_url, &ns, &ns_len, &isprefix) == FAILURE) {
                return;
        }
 
-       zend_restore_error_handling(&error_handling);
-
        docp = is_url ? xmlReadFile(data, NULL, options) : xmlReadMemory(data, data_len, NULL, NULL, options);
 
        if (!docp) {
index 8e89c4d4f91d8b296ccee32f85d094b3b96fe3af..5f34ac4fcba52697e11c705c7c3b942c5a44d6b4 100644 (file)
@@ -1807,19 +1807,14 @@ PHP_METHOD(snmp, __construct)
        zend_long retries = SNMP_DEFAULT_RETRIES;
        zend_long version = SNMP_DEFAULT_VERSION;
        int argc = ZEND_NUM_ARGS();
-       zend_error_handling error_handling;
 
        snmp_object = Z_SNMP_P(object);
-       zend_replace_error_handling(EH_THROW, NULL, &error_handling);
 
-       if (zend_parse_parameters(argc, "lss|ll", &version, &a1, &a1_len, &a2, &a2_len, &timeout, &retries) == FAILURE) {
-               zend_restore_error_handling(&error_handling);
+       if (zend_parse_parameters_throw(argc, "lss|ll", &version, &a1, &a1_len, &a2, &a2_len, &timeout, &retries) == FAILURE) {
                return;
        }
 
-       zend_restore_error_handling(&error_handling);
-
-       switch(version) {
+       switch (version) {
                case SNMP_VERSION_1:
                case SNMP_VERSION_2c:
                case SNMP_VERSION_3:
index 5e62bad6e452334a5d7f7c1334a93cdbdcdec91f..a919d4bb5ef988227cb3112f8ec463db54310c6f 100644 (file)
@@ -1220,21 +1220,17 @@ SPL_METHOD(Array, __construct)
        zval *array;
        zend_long ar_flags = 0;
        zend_class_entry *ce_get_iterator = spl_ce_Iterator;
-       zend_error_handling error_handling;
 
        if (ZEND_NUM_ARGS() == 0) {
                return; /* nothing to do */
        }
 
-       zend_replace_error_handling(EH_THROW, spl_ce_InvalidArgumentException, &error_handling);
-
-       intern = Z_SPLARRAY_P(object);
-
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|lC", &array, &ar_flags, &ce_get_iterator) == FAILURE) {
-               zend_restore_error_handling(&error_handling);
+       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "z|lC", &array, &ar_flags, &ce_get_iterator) == FAILURE) {
                return;
        }
 
+       intern = Z_SPLARRAY_P(object);
+
        if (ZEND_NUM_ARGS() > 2) {
                intern->ce_get_iterator = ce_get_iterator;
        }
@@ -1242,9 +1238,6 @@ SPL_METHOD(Array, __construct)
        ar_flags &= ~SPL_ARRAY_INT_MASK;
 
        spl_array_set_array(object, intern, array, ar_flags, ZEND_NUM_ARGS() == 1);
-
-       zend_restore_error_handling(&error_handling);
-
 }
  /* }}} */
 
index b91e8b05585bff443eca7fb84c73cad0c1a247df..3e250b1accff3e86d973b04c1a7b57e06643109e 100644 (file)
@@ -1102,11 +1102,7 @@ SPL_METHOD(DirectoryIterator, isDot)
 
 /* {{{ proto void SplFileInfo::__construct(string file_name)
  Cronstructs a new SplFileInfo from a path. */
-/* zend_replace_error_handling() is used to throw exceptions in case
-   the constructor fails. Here we use this to ensure the object
-   has a valid directory resource.
-
-   When the constructor gets called the object is already created
+/* When the constructor gets called the object is already created
    by the engine, so we must only call 'additional' initializations.
  */
 SPL_METHOD(SplFileInfo, __construct)
@@ -1114,12 +1110,8 @@ SPL_METHOD(SplFileInfo, __construct)
        spl_filesystem_object *intern;
        char *path;
        size_t len;
-       zend_error_handling error_handling;
-
-       zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling);
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &path, &len) == FAILURE) {
-               zend_restore_error_handling(&error_handling);
+       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &path, &len) == FAILURE) {
                return;
        }
 
@@ -1127,8 +1119,6 @@ SPL_METHOD(SplFileInfo, __construct)
 
        spl_filesystem_info_set_filename(intern, path, len, 1);
 
-       zend_restore_error_handling(&error_handling);
-
        /* intern->type = SPL_FS_INFO; already set */
 }
 /* }}} */
@@ -2272,18 +2262,15 @@ SPL_METHOD(SplFileObject, __construct)
        size_t   tmp_path_len;
        zend_error_handling error_handling;
 
-       zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling);
-
        intern->u.file.open_mode = NULL;
        intern->u.file.open_mode_len = 0;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|sbr!",
+       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "p|sbr!",
                        &intern->file_name, &intern->file_name_len,
                        &intern->u.file.open_mode, &intern->u.file.open_mode_len,
                        &use_include_path, &intern->u.file.zcontext) == FAILURE) {
                intern->u.file.open_mode = NULL;
                intern->file_name = NULL;
-               zend_restore_error_handling(&error_handling);
                return;
        }
 
@@ -2292,6 +2279,8 @@ SPL_METHOD(SplFileObject, __construct)
                intern->u.file.open_mode_len = 1;
        }
 
+       zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling);
+
        if (spl_filesystem_file_open(intern, use_include_path, 0) == SUCCESS) {
                tmp_path_len = strlen(intern->u.file.stream->orig_path);
 
@@ -2331,10 +2320,7 @@ SPL_METHOD(SplTempFileObject, __construct)
        spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
        zend_error_handling error_handling;
 
-       zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling);
-
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &max_memory) == FAILURE) {
-               zend_restore_error_handling(&error_handling);
+       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "|l", &max_memory) == FAILURE) {
                return;
        }
 
@@ -2351,6 +2337,7 @@ SPL_METHOD(SplTempFileObject, __construct)
        intern->u.file.open_mode = "wb";
        intern->u.file.open_mode_len = 1;
 
+       zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling);
        if (spl_filesystem_file_open(intern, 0, 0) == SUCCESS) {
                intern->_path_len = 0;
                intern->_path = estrndup("", 0);
index 9dbfa61344edd1e5fe5895e6f493fb9f7ecdc9ec..48e9d2f85f3e8a69fc05aae33ab2b8f775f70b62 100644 (file)
@@ -561,14 +561,7 @@ SPL_METHOD(SplFixedArray, __construct)
        spl_fixedarray_object *intern;
        zend_long size = 0;
 
-       int rv;
-       zend_error_handling zeh;
-
-       zend_replace_error_handling(EH_THROW, spl_ce_InvalidArgumentException, &zeh TSRMLS_CC);
-       rv = zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &size);
-       zend_restore_error_handling(&zeh TSRMLS_CC);
-
-       if (rv == FAILURE) {
+       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "|l", &size) == FAILURE) {
                return;
        }
 
index 3ffb8f7becc817f7129b08c0bf3223be3fa82b9d..e2267cfdcd76bb0f5c1c5dee21012a367f9a8fa6 100644 (file)
@@ -1067,6 +1067,8 @@ static void spl_recursive_tree_iterator_get_entry(spl_recursive_it_object *objec
 
        data = iterator->funcs->get_current_data(iterator);
 
+       /* Replace exception handling so the catchable fatal error that is thrown when a class
+        * without __toString is converted to string is converted into an exception. */
        zend_replace_error_handling(EH_THROW, spl_ce_UnexpectedValueException, &error_handling);
        if (data) {
                RETVAL_ZVAL(data, 1, 0);
@@ -1459,25 +1461,20 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
                return NULL;
        }
 
-       zend_replace_error_handling(EH_THROW, spl_ce_InvalidArgumentException, &error_handling);
-
        intern->dit_type = dit_type;
        switch (dit_type) {
                case DIT_LimitIterator: {
                        intern->u.limit.offset = 0; /* start at beginning */
                        intern->u.limit.count = -1; /* get all */
-                       if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|ll", &zobject, ce_inner, &intern->u.limit.offset, &intern->u.limit.count) == FAILURE) {
-                               zend_restore_error_handling(&error_handling);
+                       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "O|ll", &zobject, ce_inner, &intern->u.limit.offset, &intern->u.limit.count) == FAILURE) {
                                return NULL;
                        }
                        if (intern->u.limit.offset < 0) {
                                zend_throw_exception(spl_ce_OutOfRangeException, "Parameter offset must be >= 0", 0);
-                               zend_restore_error_handling(&error_handling);
                                return NULL;
                        }
                        if (intern->u.limit.count < 0 && intern->u.limit.count != -1) {
                                zend_throw_exception(spl_ce_OutOfRangeException, "Parameter count must either be -1 or a value greater than or equal 0", 0);
-                               zend_restore_error_handling(&error_handling);
                                return NULL;
                        }
                        break;
@@ -1485,13 +1482,11 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
                case DIT_CachingIterator:
                case DIT_RecursiveCachingIterator: {
                        zend_long flags = CIT_CALL_TOSTRING;
-                       if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|l", &zobject, ce_inner, &flags) == FAILURE) {
-                               zend_restore_error_handling(&error_handling);
+                       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "O|l", &zobject, ce_inner, &flags) == FAILURE) {
                                return NULL;
                        }
                        if (spl_cit_check_flags(flags) != SUCCESS) {
                                zend_throw_exception(spl_ce_InvalidArgumentException, "Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER", 0);
-                               zend_restore_error_handling(&error_handling);
                                return NULL;
                        }
                        intern->u.caching.flags |= flags & CIT_PUBLIC;
@@ -1502,8 +1497,7 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
                        zend_class_entry *ce_cast;
                        zend_string *class_name;
 
-                       if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|S", &zobject, ce_inner, &class_name) == FAILURE) {
-                               zend_restore_error_handling(&error_handling);
+                       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "O|S", &zobject, ce_inner, &class_name) == FAILURE) {
                                return NULL;
                        }
                        ce = Z_OBJCE_P(zobject);
@@ -1514,7 +1508,6 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
                                        || !ce_cast->get_iterator
                                        ) {
                                                zend_throw_exception(spl_ce_LogicException, "Class to downcast to not found or not base class or does not implement Traversable", 0);
-                                               zend_restore_error_handling(&error_handling);
                                                return NULL;
                                        }
                                        ce = ce_cast;
@@ -1523,12 +1516,10 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
                                        zend_call_method_with_0_params(zobject, ce, &ce->iterator_funcs.zf_new_iterator, "getiterator", &retval);
                                        if (EG(exception)) {
                                                zval_ptr_dtor(&retval);
-                                               zend_restore_error_handling(&error_handling);
                                                return NULL;
                                        }
                                        if (Z_TYPE(retval) != IS_OBJECT || !instanceof_function(Z_OBJCE(retval), zend_ce_traversable)) {
                                                zend_throw_exception_ex(spl_ce_LogicException, 0, "%s::getIterator() must return an object that implements Traversable", ce->name->val);
-                                               zend_restore_error_handling(&error_handling);
                                                return NULL;
                                        }
                                        zobject = &retval;
@@ -1539,6 +1530,7 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
                        break;
                }
                case DIT_AppendIterator:
+                       zend_replace_error_handling(EH_THROW, spl_ce_InvalidArgumentException, &error_handling);
                        spl_instantiate(spl_ce_ArrayIterator, &intern->u.append.zarrayit);
                        zend_call_method_with_0_params(&intern->u.append.zarrayit, spl_ce_ArrayIterator, &spl_ce_ArrayIterator->constructor, "__construct", NULL);
                        intern->u.append.iterator = spl_ce_ArrayIterator->get_iterator(spl_ce_ArrayIterator, &intern->u.append.zarrayit, 0);
@@ -1553,21 +1545,22 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
                        intern->u.regex.use_flags = ZEND_NUM_ARGS() >= 5;
                        intern->u.regex.flags = 0;
                        intern->u.regex.preg_flags = 0;
-                       if (zend_parse_parameters(ZEND_NUM_ARGS(), "OS|lll", &zobject, ce_inner, &regex, &mode, &intern->u.regex.flags, &intern->u.regex.preg_flags) == FAILURE) {
-                               zend_restore_error_handling(&error_handling);
+                       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "OS|lll", &zobject, ce_inner, &regex, &mode, &intern->u.regex.flags, &intern->u.regex.preg_flags) == FAILURE) {
                                return NULL;
                        }
                        if (mode < 0 || mode >= REGIT_MODE_MAX) {
                                zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Illegal mode %pd", mode);
-                               zend_restore_error_handling(&error_handling);
                                return NULL;
                        }
                        intern->u.regex.mode = mode;
                        intern->u.regex.regex = zend_string_copy(regex);
+
+                       zend_replace_error_handling(EH_THROW, spl_ce_InvalidArgumentException, &error_handling);
                        intern->u.regex.pce = pcre_get_compiled_regex_cache(regex);
+                       zend_restore_error_handling(&error_handling);
+
                        if (intern->u.regex.pce == NULL) {
                                /* pcre_get_compiled_regex_cache has already sent error */
-                               zend_restore_error_handling(&error_handling);
                                return NULL;
                        }
                        intern->u.regex.pce->refcount++;
@@ -1578,8 +1571,7 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
                case DIT_RecursiveCallbackFilterIterator: {
                        _spl_cbfilter_it_intern *cfi = emalloc(sizeof(*cfi));
                        cfi->fci.object = NULL;
-                       if (zend_parse_parameters(ZEND_NUM_ARGS(), "Of", &zobject, ce_inner, &cfi->fci, &cfi->fcc) == FAILURE) {
-                               zend_restore_error_handling(&error_handling);
+                       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "Of", &zobject, ce_inner, &cfi->fci, &cfi->fcc) == FAILURE) {
                                efree(cfi);
                                return NULL;
                        }
@@ -1592,15 +1584,12 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
                        break;
                }
                default:
-                       if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &zobject, ce_inner) == FAILURE) {
-                               zend_restore_error_handling(&error_handling);
+                       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "O", &zobject, ce_inner) == FAILURE) {
                                return NULL;
                        }
                        break;
        }
 
-       zend_restore_error_handling(&error_handling);
-
        if (inc_refcount) {
                ZVAL_COPY(&intern->inner.zobject, zobject);
        } else {
index 619ed3883aae28ec353ca3e3ca1246d2674af115..76933a8228920b67a1ad1d64c4c20acbcf1e509e 100644 (file)
@@ -976,18 +976,13 @@ SPL_METHOD(MultipleIterator, __construct)
 {
        spl_SplObjectStorage   *intern;
        zend_long               flags = MIT_NEED_ALL|MIT_KEYS_NUMERIC;
-       zend_error_handling error_handling;
 
-       zend_replace_error_handling(EH_THROW, spl_ce_InvalidArgumentException, &error_handling);
-
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &flags) == FAILURE) {
-               zend_restore_error_handling(&error_handling);
+       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "|l", &flags) == FAILURE) {
                return;
        }
 
        intern = Z_SPLOBJSTORAGE_P(getThis());
        intern->flags = flags;
-       zend_restore_error_handling(&error_handling);
 }
 /* }}} */
 
index bc4fd146472a100785981d4ab45f537fd87da5de..1f71d3032a48df339291fc1085f3ba5f6504434c 100644 (file)
@@ -10,27 +10,25 @@ set_error_handler(function($errno, $errstr){
 
 try {
        new CallbackFilterIterator();
-} catch(InvalidArgumentException $e) {
+} catch (TypeException $e) {
        echo $e->getMessage() . "\n";
 }
 
 try {
        new CallbackFilterIterator(null);
-} catch(InvalidArgumentException $e) {
-       echo $e->getMessage() . "\n";
-} catch(EngineException $e) {
+} catch (TypeException $e) {
        echo $e->getMessage() . "\n";
 }
 
 try {
        new CallbackFilterIterator(new ArrayIterator(array()), null);
-} catch(InvalidArgumentException $e) {
+} catch (TypeException $e) {
        echo $e->getMessage() . "\n";
 }
 
 try {
        new CallbackFilterIterator(new ArrayIterator(array()), array());
-} catch(InvalidArgumentException $e) {
+} catch (TypeException $e) {
        echo $e->getMessage() . "\n";
 }
 
index aa5933ebdbef202fcaf72dca989625d88a7fbb0d..e1515c4039a7d414a391be010df5ebe6223a32c9 100644 (file)
@@ -7,11 +7,10 @@ PHPNW Test Fest 2009 - Jordan Hatch
 
 try {
        $array = new SplFixedArray( array("string", 1) );
-}
-catch(InvalidArgumentException $iae) {
+} catch (TypeException $iae) {
        echo "Ok - ".$iae->getMessage().PHP_EOL;
 }
 
 ?>
 --EXPECTF--
-Ok - SplFixedArray::__construct() expects parameter 1 to be integer, array given
\ No newline at end of file
+Ok - SplFixedArray::__construct() expects parameter 1 to be integer, array given
index 411d7402df044193084e2a7ed46e7b9725ead475..66c7fe6a592b33d1eec7cb663e1ff1523ab8968b 100644 (file)
@@ -6,8 +6,7 @@ PHPNW Test Fest 2009 - Jordan Hatch
 <?php
 try {
        $array = new SplFixedArray( "string" );
-}
-catch(InvalidArgumentException $iae) {
+} catch (TypeException $iae) {
        echo "Ok - ".$iae->getMessage().PHP_EOL;
 }
 
index 10d4c64a0c5245026e6590cda3f46859b430988e..20f4e7970c903350dc62f68ee012b3f4b31468ef 100644 (file)
@@ -6,8 +6,7 @@ Philip Norton philipnorton42@gmail.com
 <?php
 try {
        $array = new SplFixedArray(new SplFixedArray(3));
-}
-catch(InvalidArgumentException $iae) {
+} catch (TypeException $iae) {
        echo "Ok - ".$iae->getMessage().PHP_EOL;
 }
 
index a6c71717b55c00b6a3748202cbd695a7a655aee4..8eb306689d1273ed5947e27238dbfbb5c18d3667 100644 (file)
@@ -2,11 +2,11 @@
 SPL SplTempFileObject constructor sets correct defaults when pass 0 arguments
 --FILE--
 <?php
-new SplTempFileObject('invalid');
+try {
+    new SplTempFileObject('invalid');
+} catch (TypeException $e) {
+    echo $e->getMessage(), "\n";
+}
 ?>
 --EXPECTF--
-Fatal error: Uncaught exception 'RuntimeException' with message 'SplTempFileObject::__construct() expects parameter 1 to be integer, string given' in %s
-Stack trace:
-#0 %s: SplTempFileObject->__construct('invalid')
-#1 {main}
-  thrown in %s
+SplTempFileObject::__construct() expects parameter 1 to be integer, string given
index 21c312d2d0bff07af3753ab6f014633b59622073..cff0dd048d96217980ced7e04858e97b84b73d94 100644 (file)
@@ -7,14 +7,14 @@ $a = new stdClass;
 $a->p = 1;
 try {
   var_dump(new ArrayObject($a, 0, "Exception"));
-} catch (InvalidArgumentException $e) {
+} catch (TypeException $e) {
   echo $e->getMessage() . "(" . $e->getLine() .  ")\n";
 }
 
 echo "Non-existent class:\n";
 try {
   var_dump(new ArrayObject(new stdClass, 0, "nonExistentClassName"));
-} catch (InvalidArgumentException $e) {
+} catch (TypeException $e) {
   echo $e->getMessage() . "(" . $e->getLine() .  ")\n";
 }
 ?>
index 850a2cb3fce9bc3e00ba2eb36677719bb3125dd7..d075516725222de7963fc12617d92681cf198b72 100644 (file)
@@ -13,10 +13,10 @@ Class C implements Iterator {
 
 try {
   var_dump(new ArrayObject(new stdClass, 0, "C", "extra"));
-} catch (InvalidArgumentException $e) {
+} catch (TypeException $e) {
   echo $e->getMessage() . "(" . $e->getLine() .  ")\n";
 }
 ?>
 --EXPECTF--
 Too many arguments:
-ArrayObject::__construct() expects at most 3 parameters, 4 given(12)
\ No newline at end of file
+ArrayObject::__construct() expects at most 3 parameters, 4 given(12)
index 4715eea9863b8561de9da614eb196ca7a597c58c..b4c3756cb50c9203eeee616400be48360922b301 100644 (file)
@@ -28,7 +28,7 @@ try {
   foreach($ao as $key=>$value) {
     echo "  $key=>$value\n";
   }
-} catch (Exception $e) {
+} catch (TypeException $e) {
        var_dump($e->getMessage());
 }
 
@@ -37,7 +37,7 @@ try {
   foreach($ao as $key=>$value) {
     echo "  $key=>$value\n";
   }
-} catch (Exception $e) {
+} catch (TypeException $e) {
        var_dump($e->getMessage());
 }
 
index d9175f7e6fb36ceedcfbb93a9a870555c5a01d82..44d12ee242fb6d5566fbeacd5fbf28b66fdc66fb 100644 (file)
@@ -5,7 +5,7 @@ Bug #54292 (Wrong parameter causes crash in SplFileObject::__construct())
 
 try {
        new SplFileObject('foo', array());
-} catch (Exception $e) {
+} catch (TypeException $e) {
        var_dump($e->getMessage());
 }
 
index 72970a9a1f900292f634cb7a4833049c377c6c68..83727a23b93ecf26263cfa7c4ddf091b7f15f015 100644 (file)
@@ -1,18 +1,30 @@
 --TEST--
-SPL: FixedArray: Trying to instantiate passing object to constructor parameter
+SPL: FixedArray: Invalid arguments
 --FILE--
 <?php
 
-$b = new stdClass;
-
 try {
-       $a = new SplFixedArray($b);
+       $a = new SplFixedArray(new stdClass);
+} catch (TypeException $iae) {
+       echo "Ok - ".$iae->getMessage().PHP_EOL;
 }
-catch(InvalidArgumentException $iae) {
+
+try {
+       $a = new SplFixedArray('FOO');
+} catch (TypeException $iae) {
        echo "Ok - ".$iae->getMessage().PHP_EOL;
 }
 
+try {
+       $a = new SplFixedArray('');
+} catch (TypeException $iae) {
+       echo "Ok - ".$iae->getMessage().PHP_EOL;
+}
 
 ?>
---EXPECTF--
+===DONE===
+--EXPECT--
 Ok - SplFixedArray::__construct() expects parameter 1 to be integer, object given
+Ok - SplFixedArray::__construct() expects parameter 1 to be integer, string given
+Ok - SplFixedArray::__construct() expects parameter 1 to be integer, string given
+===DONE===
index d67c7ccb6983b53f020368d6698c6316b77eca66..f255ed299a76368c4df1f789853c4cdf3d9d0d14 100644 (file)
@@ -5,8 +5,7 @@ SPL: FixedArray: Trying to instantiate passing string to construtor parameter
 
 try {
        $a = new SplFixedArray('FOO');
-}
-catch(InvalidArgumentException $iae) {
+} catch (TypeException $iae) {
        echo "Ok - ".$iae->getMessage().PHP_EOL;
 }
 ?>
index f12d83bb39188785d84cbf10d6c477be0727e921..d189d41da3e4e5a411324133197149f71d7eaba6 100644 (file)
@@ -5,8 +5,7 @@ SPL: FixedArray: accessing uninitialized array
 
 try {
        $a = new SplFixedArray('');
-}
-catch(InvalidArgumentException $iae) {
+} catch (TypeException $iae) {
        echo "Ok - ".$iae->getMessage().PHP_EOL;
 }
 
index 4b0e75a7d4ff6dc486fb7d8859257c43778c311e..ee982636383b2d9f41c1ced6df4e734482c86afb 100644 (file)
@@ -1,19 +1,64 @@
 --TEST--
-SPL: FilterIterator::__construct(void)
+SPL: Calling __construct(void) on class extending SPL iterator
 --CREDITS--
 Sebastian Schürmann
 --FILE--
 <?php
+
 class myFilterIterator extends FilterIterator {
-       function accept() {
-               
-       }
+       function accept() { }
 }
+
+class myCachingIterator extends CachingIterator { }
+
+class myRecursiveCachingIterator extends RecursiveCachingIterator { }
+
+class myParentIterator extends ParentIterator { }
+
+class myLimitIterator extends LimitIterator { }
+
+class myNoRewindIterator extends NoRewindIterator  {}
+
 try {
        $it = new myFilterIterator();   
-} catch (InvalidArgumentException $e) {
-       echo 'InvalidArgumentException thrown';
+} catch (TypeException $e) {
+    echo $e->getMessage(), "\n";
 }
+
+try {
+       $it = new myCachingIterator();  
+} catch (TypeException $e) {
+    echo $e->getMessage(), "\n";
+}
+
+try {
+       $it = new myRecursiveCachingIterator(); 
+} catch (TypeException $e) {
+    echo $e->getMessage(), "\n";
+}
+
+try {
+       $it = new myParentIterator();   
+} catch (TypeException $e) {
+    echo $e->getMessage(), "\n";
+}
+
+try {
+       $it = new myLimitIterator();
+} catch (TypeException $e) {
+    echo $e->getMessage(), "\n";
+}
+try {
+       $it = new myNoRewindIterator();
+} catch (TypeException $e) {
+    echo $e->getMessage(), "\n";
+}
+
 ?>
 --EXPECT--
-InvalidArgumentException thrown
+FilterIterator::__construct() expects exactly 1 parameter, 0 given
+CachingIterator::__construct() expects at least 1 parameter, 0 given
+RecursiveCachingIterator::__construct() expects at least 1 parameter, 0 given
+ParentIterator::__construct() expects exactly 1 parameter, 0 given
+LimitIterator::__construct() expects at least 1 parameter, 0 given
+NoRewindIterator::__construct() expects exactly 1 parameter, 0 given
diff --git a/ext/spl/tests/iterator_059.phpt b/ext/spl/tests/iterator_059.phpt
deleted file mode 100644 (file)
index 8c579ae..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
---TEST--
-SPL: CachingIterator::__construct(void)
---CREDITS--
-Sebastian Schürmann
---FILE--
-<?php
-class myCachingIterator extends CachingIterator {
-       
-}
-try {
-       $it = new myCachingIterator();  
-} catch (InvalidArgumentException $e) {
-       echo 'InvalidArgumentException thrown';
-}
-?>
---EXPECT--
-InvalidArgumentException thrown
diff --git a/ext/spl/tests/iterator_060.phpt b/ext/spl/tests/iterator_060.phpt
deleted file mode 100644 (file)
index 0c3b6c2..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
---TEST--
-SPL: RecursiveCachingIterator::__construct(void)
---CREDITS--
-Sebastian Schürmann
---FILE--
-<?php
-class myRecursiveCachingIterator extends RecursiveCachingIterator {
-       
-}
-try {
-       $it = new myRecursiveCachingIterator(); 
-} catch (InvalidArgumentException $e) {
-       echo 'InvalidArgumentException thrown';
-}
-?>
---EXPECT--
-InvalidArgumentException thrown
diff --git a/ext/spl/tests/iterator_061.phpt b/ext/spl/tests/iterator_061.phpt
deleted file mode 100644 (file)
index 472f8da..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
---TEST--
-SPL: ParentIterator::__construct(void)
---CREDITS--
-Sebastian Schürmann
---FILE--
-<?php
-class myParentIterator extends ParentIterator {
-       
-}
-try {
-       $it = new myParentIterator();   
-} catch (InvalidArgumentException $e) {
-       echo 'InvalidArgumentException thrown';
-}
-?>
---EXPECT--
-InvalidArgumentException thrown
diff --git a/ext/spl/tests/iterator_063.phpt b/ext/spl/tests/iterator_063.phpt
deleted file mode 100644 (file)
index 4d4112b..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
---TEST--
-SPL: LimitIterator::__construct(void)
---CREDITS--
-Sebastian Schürmann
---FILE--
-<?php
-class myLimitIterator extends LimitIterator {
-       
-}
-try {
-       $it = new myLimitIterator();
-} catch (InvalidArgumentException $e) {
-       echo 'InvalidArgumentException thrown';
-}
-?>
---EXPECT--
-InvalidArgumentException thrown
diff --git a/ext/spl/tests/iterator_064.phpt b/ext/spl/tests/iterator_064.phpt
deleted file mode 100644 (file)
index 6a62e6c..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
---TEST--
-SPL: CachingIterator::__construct(void)
---CREDITS--
-Sebastian Schürmann
---FILE--
-<?php
-class myCachingIterator  extends CachingIterator  {}
-try {
-       $it = new myCachingIterator();
-} catch (InvalidArgumentException $e) {
-       echo 'InvalidArgumentException thrown';
-}
-?>
---EXPECT--
-InvalidArgumentException thrown
diff --git a/ext/spl/tests/iterator_065.phpt b/ext/spl/tests/iterator_065.phpt
deleted file mode 100644 (file)
index 9ea2974..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
---TEST--
-SPL: RecursiveCachingIterator::__construct(void)
---CREDITS--
-Sebastian Schürmann
---FILE--
-<?php
-class myRecursiveCachingIterator  extends RecursiveCachingIterator  {}
-try {
-       $it = new myRecursiveCachingIterator();
-} catch (InvalidArgumentException $e) {
-       echo 'InvalidArgumentException thrown';
-}
-?>
---EXPECT--
-InvalidArgumentException thrown
diff --git a/ext/spl/tests/iterator_066.phpt b/ext/spl/tests/iterator_066.phpt
deleted file mode 100644 (file)
index 008c47c..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
---TEST--
-SPL: NoRewindIterator::__construct(void)
---CREDITS--
-Sebastian Schürmann
---FILE--
-<?php
-class myNoRewindIterator extends NoRewindIterator  {}
-try {
-       $it = new myNoRewindIterator();
-} catch (InvalidArgumentException $e) {
-       echo 'InvalidArgumentException thrown';
-}
-?>
---EXPECT--
-InvalidArgumentException thrown
index 83c8553942bf26ef77bbeedbd5f26cf36ce6cec6..4cc7000a19f0f4f7f3aca881f2929f566621f3a4 100644 (file)
@@ -1,16 +1,14 @@
 --TEST--
 SPL: RecursiveTreeIterator(non-traversable)
---INI--
-error_reporting=E_ALL&~E_NOTICE
 --FILE--
 <?php
 try {
        new RecursiveTreeIterator(new ArrayIterator(array()));
-} catch (InvalidArgumentException $e) {
-       echo "InvalidArgumentException thrown\n";
+} catch (TypeException $e) {
+    echo $e->getMessage(), "\n";
 }
 ?>
 ===DONE===
---EXPECTF--
-InvalidArgumentException thrown
+--EXPECT--
+RecursiveCachingIterator::__construct() expects parameter 1 to be RecursiveIterator, object given
 ===DONE===
index d4fdb14c13fb8eb920391ea05adf52087d23d834..ec103f5c9cbf98c232af1610a3b2d6a28e507c72 100644 (file)
@@ -6,23 +6,19 @@ TestFest London May 2009
 --FILE--
 <?php
 
-  //I think this is testing line 1297 of spl_iterators.c
-
-  $array = array(array(7,8,9),1,2,3,array(4,5,6));
+$array = array(array(7,8,9),1,2,3,array(4,5,6));
 $arrayIterator = new ArrayIterator($array);
 try {
-$test = new IteratorIterator($arrayIterator);
-
-$test = new IteratorIterator($arrayIterator, 1);
-$test = new IteratorIterator($arrayIterator, 1, 1);
-$test = new IteratorIterator($arrayIterator, 1, 1, 1);
-$test = new IteratorIterator($arrayIterator, 1, 1, 1, 1);
+    $test = new IteratorIterator($arrayIterator);
 
-} catch (InvalidArgumentException $e){
-  print  $e->getMessage() . "\n";
+    $test = new IteratorIterator($arrayIterator, 1);
+    $test = new IteratorIterator($arrayIterator, 1, 1);
+    $test = new IteratorIterator($arrayIterator, 1, 1, 1);
+    $test = new IteratorIterator($arrayIterator, 1, 1, 1, 1);
+} catch (TypeException $e){
+  echo $e->getMessage() . "\n";
 }
 
-
 ?>
 ===DONE===
 --EXPECTF--
index 028881f21a490ba7acc7be2dde0eeb8cb7516e06..94172048ca6a499e5cb2a7b0e07e3e9e888be412 100644 (file)
@@ -103,18 +103,13 @@ PHP_METHOD(sqlite3, open)
        char *filename, *encryption_key, *fullpath;
        size_t filename_len, encryption_key_len = 0;
        zend_long flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
-       zend_error_handling error_handling;
 
        db_obj = Z_SQLITE3_DB_P(object);
-       zend_replace_error_handling(EH_THROW, NULL, &error_handling);
 
-       if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "p|ls", &filename, &filename_len, &flags, &encryption_key, &encryption_key_len)) {
-               zend_restore_error_handling(&error_handling);
+       if (FAILURE == zend_parse_parameters_throw(ZEND_NUM_ARGS(), "p|ls", &filename, &filename_len, &flags, &encryption_key, &encryption_key_len)) {
                return;
        }
 
-       zend_restore_error_handling(&error_handling);
-
        if (db_obj->initialised) {
                zend_throw_exception(zend_exception_get_default(), "Already initialised DB Object", 0);
        }
@@ -1600,17 +1595,15 @@ PHP_METHOD(sqlite3stmt, __construct)
        php_sqlite3_free_list *free_item;
 
        stmt_obj = Z_SQLITE3_STMT_P(object);
-       zend_replace_error_handling(EH_THROW, NULL, &error_handling);
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "OS", &db_zval, php_sqlite3_sc_entry, &sql) == FAILURE) {
-               zend_restore_error_handling(&error_handling);
+       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "OS", &db_zval, php_sqlite3_sc_entry, &sql) == FAILURE) {
                return;
        }
 
        db_obj = Z_SQLITE3_DB_P(db_zval);
 
+       zend_replace_error_handling(EH_THROW, NULL, &error_handling);
        SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3)
-
        zend_restore_error_handling(&error_handling);
 
        if (!sql->len) {
index f9155e7d79ab24edcdca128c725ebbda66dd8019..985033b33ec586a803d6eafef2c8e14d6641d82e 100644 (file)
@@ -10,7 +10,7 @@ Felix De Vliegher
 
 try {
   $db = new SQLite3();
-} catch (Exception $e) {
+} catch (TypeException $e) {
   var_dump($e->getMessage());
 }