Browse Source

Always throw TypeException on throwing zpp failures

Introduces a ZEND_PARSE_PARAMS_THROW flag for zpp, which forces to
report FAILURE errors using a TypeException instead of a Warning,
like it would happen in strict mode.

Adds a zend_parse_parameters_throw() convenience function, which
invokes zpp with this flag.

Converts all cases I could identify, where we currently have
throwing zpp usage in constructors and replaces them with this API.
Error handling is still replaced to EH_THROW in some cases to handle
other, domain-specific errors in constructors.
pull/1215/merge
Nikita Popov 11 years ago
parent
commit
122d759618
  1. 4
      Zend/zend.c
  2. 2
      Zend/zend.h
  3. 44
      Zend/zend_API.c
  4. 2
      Zend/zend_API.h
  5. 40
      ext/date/php_date.c
  6. 15
      ext/date/tests/DateTimeZone_construct_error.phpt
  7. 2
      ext/date/tests/DateTimeZone_construct_variation1.phpt
  8. 14
      ext/date/tests/DateTime_construct_error.phpt
  9. 4
      ext/date/tests/DateTime_construct_variation1.phpt
  10. 2
      ext/date/tests/DateTime_construct_variation2.phpt
  11. 8
      ext/dom/attr.c
  12. 8
      ext/dom/cdatasection.c
  13. 8
      ext/dom/comment.c
  14. 8
      ext/dom/document.c
  15. 8
      ext/dom/documentfragment.c
  16. 8
      ext/dom/element.c
  17. 9
      ext/dom/entityreference.c
  18. 9
      ext/dom/processinginstruction.c
  19. 12
      ext/dom/tests/DOMAttr_construct_error_001.phpt
  20. 10
      ext/dom/tests/DOMCDATASection_construct_error_001.phpt
  21. 12
      ext/dom/tests/DOMComment_construct_error_001.phpt
  22. 12
      ext/dom/tests/DOMDocumentFragment_construct_error_001.phpt
  23. 8
      ext/dom/text.c
  24. 8
      ext/dom/xpath.c
  25. 14
      ext/fileinfo/fileinfo.c
  26. 14
      ext/fileinfo/tests/bug61173.phpt
  27. 14
      ext/fileinfo/tests/finfo_open_error.phpt
  28. 3
      ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp
  29. 13
      ext/intl/calendar/gregoriancalendar_methods.cpp
  30. 9
      ext/intl/collator/collator_create.c
  31. 11
      ext/intl/converter/converter.c
  32. 9
      ext/intl/dateformat/dateformat_create.cpp
  33. 9
      ext/intl/formatter/formatter_main.c
  34. 10
      ext/intl/intl_error.c
  35. 8
      ext/intl/intl_error.h
  36. 9
      ext/intl/msgformat/msgformat.c
  37. 9
      ext/intl/resourcebundle/resourcebundle_class.c
  38. 7
      ext/intl/spoofchecker/spoofchecker_create.c
  39. 6
      ext/intl/tests/breakiter___construct_error.phpt
  40. 17
      ext/intl/tests/formatter_fail.phpt
  41. 2
      ext/intl/tests/gregoriancalendar___construct_error.phpt
  42. 25
      ext/intl/tests/msgfmt_fail.phpt
  43. 25
      ext/intl/tests/msgfmt_fail2.phpt
  44. 6
      ext/pdo/pdo_dbh.c
  45. 2
      ext/pdo_mysql/tests/pdo_mysql___construct.phpt
  46. 2
      ext/pdo_mysql/tests/pdo_mysql___construct_options.phpt
  47. 21
      ext/phar/phar_object.c
  48. 2
      ext/phar/tests/badparameters.phpt
  49. 10
      ext/phar/tests/bug60261.phpt
  50. 15
      ext/phar/tests/pharfileinfo_construct.phpt
  51. 86
      ext/reflection/php_reflection.c
  52. 9
      ext/reflection/tests/ReflectionExtension_constructor_error.phpt
  53. 14
      ext/reflection/tests/ReflectionFunction_construct.001.phpt
  54. 6
      ext/reflection/tests/ReflectionMethod_006.phpt
  55. 6
      ext/reflection/tests/ReflectionMethod_constructor_error2.phpt
  56. 2
      ext/reflection/tests/ReflectionParameter_invalidMethodInConstructor.phpt
  57. 9
      ext/reflection/tests/ReflectionProperty_error.phpt
  58. 7
      ext/simplexml/simplexml.c
  59. 9
      ext/snmp/snmp.c
  60. 13
      ext/spl/spl_array.c
  61. 27
      ext/spl/spl_directory.c
  62. 9
      ext/spl/spl_fixedarray.c
  63. 37
      ext/spl/spl_iterators.c
  64. 7
      ext/spl/spl_observer.c
  65. 10
      ext/spl/tests/CallbackFilterIteratorTest-002.phpt
  66. 5
      ext/spl/tests/SplFixedArray__construct_param_array.phpt
  67. 3
      ext/spl/tests/SplFixedArray__construct_param_string.phpt
  68. 3
      ext/spl/tests/SplFixedArray_construct_param_SplFixedArray.phpt
  69. 12
      ext/spl/tests/SplTempFileObject_constructor_error.phpt
  70. 4
      ext/spl/tests/arrayObject___construct_error1.phpt
  71. 4
      ext/spl/tests/arrayObject___construct_error2.phpt
  72. 4
      ext/spl/tests/arrayObject_setIteratorClass_error1.phpt
  73. 2
      ext/spl/tests/bug54292.phpt
  74. 24
      ext/spl/tests/fixedarray_005.phpt
  75. 3
      ext/spl/tests/fixedarray_009.phpt
  76. 3
      ext/spl/tests/fixedarray_015.phpt
  77. 59
      ext/spl/tests/iterator_056.phpt
  78. 17
      ext/spl/tests/iterator_059.phpt
  79. 17
      ext/spl/tests/iterator_060.phpt
  80. 17
      ext/spl/tests/iterator_061.phpt
  81. 17
      ext/spl/tests/iterator_063.phpt
  82. 15
      ext/spl/tests/iterator_064.phpt
  83. 15
      ext/spl/tests/iterator_065.phpt
  84. 15
      ext/spl/tests/iterator_066.phpt
  85. 10
      ext/spl/tests/recursive_tree_iterator_003.phpt
  86. 20
      ext/spl/tests/spl_iterator_iterator_constructor.phpt
  87. 13
      ext/sqlite3/sqlite3.c
  88. 2
      ext/sqlite3/tests/sqlite3_02_open.phpt

4
Zend/zend.c

@ -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);

2
Zend/zend.h

@ -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);

44
Zend/zend_API.c

@ -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;

2
Zend/zend_API.h

@ -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, ...);

40
ext/date/php_date.c

@ -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);
}

15
ext/date/tests/DateTimeZone_construct_error.phpt

@ -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
DateTimeZone::__construct() expects exactly 1 parameter, 2 given
===DONE===

2
ext/date/tests/DateTimeZone_construct_variation1.phpt

@ -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";
}

14
ext/date/tests/DateTime_construct_error.phpt

@ -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
DateTime::__construct() expects at most 2 parameters, 3 given
===DONE===

4
ext/date/tests/DateTime_construct_variation1.phpt

@ -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";
}

2
ext/date/tests/DateTime_construct_variation2.phpt

@ -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";
}

8
ext/dom/attr.c

@ -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);

8
ext/dom/cdatasection.c

@ -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) {

8
ext/dom/comment.c

@ -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) {

8
ext/dom/document.c

@ -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) {

8
ext/dom/documentfragment.c

@ -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) {

8
ext/dom/element.c

@ -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) {

9
ext/dom/entityreference.c

@ -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);

9
ext/dom/processinginstruction.c

@ -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);

12
ext/dom/tests/DOMAttr_construct_error_001.phpt

@ -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

10
ext/dom/tests/DOMCDATASection_construct_error_001.phpt

@ -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
DOMCdataSection::__construct() expects exactly 1 parameter, 0 given

12
ext/dom/tests/DOMComment_construct_error_001.phpt

@ -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
DOMComment::__construct() expects at most 1 parameter, 2 given

12
ext/dom/tests/DOMDocumentFragment_construct_error_001.phpt

@ -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
DOMDocumentFragment::__construct() expects exactly 0 parameters, 1 given

8
ext/dom/text.c

@ -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) {

8
ext/dom/xpath.c

@ -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);

14
ext/fileinfo/fileinfo.c

@ -294,23 +294,17 @@ PHP_FUNCTION(finfo_open)
FILEINFO_DECLARE_INIT_OBJECT(object)
char resolved_path[MAXPATHLEN];
zend_error_handling zeh;
int flags = object ? ZEND_PARSE_PARAMS_THROW : 0;
if (object) {
zend_replace_error_handling(EH_THROW, NULL, &zeh);
}
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|lp", &options, &file, &file_len) == FAILURE) {
if (object) {
zend_restore_error_handling(&zeh);
if (!EG(exception)) {
zend_throw_exception(NULL, "Constructor failed", 0);
}
}
if (zend_parse_parameters_ex(flags, ZEND_NUM_ARGS(), "|lp", &options, &file, &file_len) == FAILURE) {
RETURN_FALSE;
}
if (object) {
finfo_object *finfo_obj = Z_FINFO_P(object);
zend_replace_error_handling(EH_THROW, NULL, &zeh);
if (finfo_obj->ptr) {
magic_close(finfo_obj->ptr->magic);
efree(finfo_obj->ptr);

14
ext/fileinfo/tests/bug61173.phpt

@ -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

14
ext/fileinfo/tests/finfo_open_error.phpt

@ -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===

3
ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp

@ -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);

13
ext/intl/calendar/gregoriancalendar_methods.cpp

@ -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);

9
ext/intl/collator/collator_create.c

@ -25,17 +25,18 @@
#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);

11
ext/intl/converter/converter.c

@ -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;
}

9
ext/intl/dateformat/dateformat_create.cpp

@ -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);

9
ext/intl/formatter/formatter_main.c

@ -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);

10
ext/intl/intl_error.c

@ -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 );

8
ext/intl/intl_error.h

@ -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 );

9
ext/intl/msgformat/msgformat.c

@ -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);

9
ext/intl/resourcebundle/resourcebundle_class.c

@ -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();
}

7
ext/intl/spoofchecker/spoofchecker_create.c

@ -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));

6
ext/intl/tests/breakiter___construct_error.phpt

@ -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 {

17
ext/intl/tests/formatter_fail.phpt

@ -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'

2
ext/intl/tests/gregoriancalendar___construct_error.phpt

@ -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--

25
ext/intl/tests/msgfmt_fail.phpt

@ -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'

25
ext/intl/tests/msgfmt_fail2.phpt

@ -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'

6
ext/pdo/pdo_dbh.c

@ -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, ':');

2
ext/pdo_mysql/tests/pdo_mysql___construct.phpt

@ -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));');

2
ext/pdo_mysql/tests/pdo_mysql___construct_options.phpt

@ -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())))

21
ext/phar/phar_object.c

@ -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;
}

2
ext/phar/tests/badparameters.phpt

@ -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 {

10
ext/phar/tests/bug60261.phpt

@ -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

15
ext/phar/tests/pharfileinfo_construct.phpt

@ -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===

86
ext/reflection/php_reflection.c

@ -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;
}

9
ext/reflection/tests/ReflectionExtension_constructor_error.phpt

@ -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;
}

14
ext/reflection/tests/ReflectionFunction_construct.001.phpt

@ -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;
}

6
ext/reflection/tests/ReflectionMethod_006.phpt

@ -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;
}

6
ext/reflection/tests/ReflectionMethod_constructor_error2.phpt

@ -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;
}

2
ext/reflection/tests/ReflectionParameter_invalidMethodInConstructor.phpt

@ -25,7 +25,7 @@ class C {
try {
new ReflectionParameter(array ('A', 'b'));
}
catch(ReflectionException $e) {
catch(TypeException $e) {
printf( "Ok - %s\n", $e->getMessage());
}

9
ext/reflection/tests/ReflectionProperty_error.phpt

@ -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;
}

7
ext/simplexml/simplexml.c

@ -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) {

9
ext/snmp/snmp.c

@ -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:

13
ext/spl/spl_array.c

@ -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);
}
/* }}} */

27
ext/spl/spl_directory.c

@ -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);

9
ext/spl/spl_fixedarray.c

@ -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;
}

37
ext/spl/spl_iterators.c

@ -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 {

7
ext/spl/spl_observer.c

@ -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);
}
/* }}} */

10
ext/spl/tests/CallbackFilterIteratorTest-002.phpt

@ -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";
}

5
ext/spl/tests/SplFixedArray__construct_param_array.phpt

@ -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
Ok - SplFixedArray::__construct() expects parameter 1 to be integer, array given

3
ext/spl/tests/SplFixedArray__construct_param_string.phpt

@ -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;
}

3
ext/spl/tests/SplFixedArray_construct_param_SplFixedArray.phpt

@ -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;
}

12
ext/spl/tests/SplTempFileObject_constructor_error.phpt

@ -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

4
ext/spl/tests/arrayObject___construct_error1.phpt

@ -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";
}
?>

4
ext/spl/tests/arrayObject___construct_error2.phpt

@ -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)
ArrayObject::__construct() expects at most 3 parameters, 4 given(12)

4
ext/spl/tests/arrayObject_setIteratorClass_error1.phpt

@ -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());
}

2
ext/spl/tests/bug54292.phpt

@ -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());
}

24
ext/spl/tests/fixedarray_005.phpt

@ -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===

3
ext/spl/tests/fixedarray_009.phpt

@ -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;
}
?>

3
ext/spl/tests/fixedarray_015.phpt

@ -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;
}

59
ext/spl/tests/iterator_056.phpt

@ -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

17
ext/spl/tests/iterator_059.phpt

@ -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

17
ext/spl/tests/iterator_060.phpt

@ -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

17
ext/spl/tests/iterator_061.phpt

@ -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

17
ext/spl/tests/iterator_063.phpt

@ -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

15
ext/spl/tests/iterator_064.phpt

@ -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

15
ext/spl/tests/iterator_065.phpt

@ -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

15
ext/spl/tests/iterator_066.phpt

@ -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

10
ext/spl/tests/recursive_tree_iterator_003.phpt

@ -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===

20
ext/spl/tests/spl_iterator_iterator_constructor.phpt

@ -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--

13
ext/sqlite3/sqlite3.c

@ -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) {

2
ext/sqlite3/tests/sqlite3_02_open.phpt

@ -10,7 +10,7 @@ Felix De Vliegher
try {
$db = new SQLite3();
} catch (Exception $e) {
} catch (TypeException $e) {
var_dump($e->getMessage());
}

Loading…
Cancel
Save