summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2015-03-30 12:14:43 +0300
committerDmitry Stogov <dmitry@zend.com>2015-03-30 12:14:43 +0300
commit9155a267adeeb6f442f97892de441e4b6666ce73 (patch)
tree7d525ab7379401c38b4416886655b4753ec5701a
parentc71c97e101f239d487c7a9797bdf193098d469ca (diff)
parent910a3243063f0490a60e5c3c0e1467a6171f4e39 (diff)
downloadphp-git-9155a267adeeb6f442f97892de441e4b6666ce73.tar.gz
Merge branch 'InternalClassClean' of github.com:Danack/php-src into InternalClassClean
* 'InternalClassClean' of github.com:Danack/php-src: Fixed indentation. Fixed comment style. Fixed commented out code. Reverted change to function name and added note of why it is different from the class it is actually changing. Made UConverter throw an exception if the constructor fails. Fixed PDO constructor to not return null. Fixed fileinfo behaviour. Made Phar throw exception on bad constructor. Converted intl extension to use IntlException in constructors. Fixed SplFixedArray and tests. Fixed ReflectionExtension and ReflectionProperty. Fixed ReflectionFunction, ReflectionMethod and ReflectionParameter. Fixed PDORow behaviour and message.
-rw-r--r--ext/fileinfo/fileinfo.c12
-rw-r--r--ext/intl/breakiterator/breakiterator_methods.cpp4
-rw-r--r--ext/intl/calendar/gregoriancalendar_methods.cpp38
-rw-r--r--ext/intl/collator/collator_create.c12
-rw-r--r--ext/intl/converter/converter.c11
-rw-r--r--ext/intl/dateformat/dateformat_create.cpp20
-rw-r--r--ext/intl/formatter/formatter_main.c14
-rw-r--r--ext/intl/intl_common.h2
-rw-r--r--ext/intl/intl_data.h4
-rw-r--r--ext/intl/intl_error.c57
-rw-r--r--ext/intl/intl_error.h6
-rw-r--r--ext/intl/msgformat/msgformat.c16
-rw-r--r--ext/intl/msgformat/msgformat_class.c4
-rw-r--r--ext/intl/resourcebundle/resourcebundle_class.c14
-rw-r--r--ext/intl/spoofchecker/spoofchecker_create.c2
-rw-r--r--ext/intl/tests/bug62017.phpt12
-rw-r--r--ext/intl/tests/formatter_fail.phpt53
-rw-r--r--ext/intl/tests/formatter_format.phpt9
-rw-r--r--ext/intl/tests/gregoriancalendar___construct_error.phpt22
-rw-r--r--ext/intl/tests/msgfmt_fail.phpt61
-rw-r--r--ext/intl/tests/msgfmt_parse.phpt14
-rw-r--r--ext/intl/tests/resourcebundle_create.phpt29
-rw-r--r--ext/intl/transliterator/transliterator_methods.c8
-rw-r--r--ext/pdo/pdo_dbh.c10
-rw-r--r--ext/pdo/pdo_stmt.c4
-rw-r--r--ext/pdo/tests/pdo_036.phpt32
-rw-r--r--ext/pdo/tests/pdorow.phpt18
-rw-r--r--ext/phar/phar_object.c21
-rw-r--r--ext/reflection/php_reflection.c80
-rw-r--r--ext/reflection/tests/ReflectionExtension_constructor_error.phpt30
-rw-r--r--ext/reflection/tests/ReflectionFunction_construct.001.phpt39
-rw-r--r--ext/reflection/tests/ReflectionMethod_006.phpt31
-rw-r--r--ext/reflection/tests/ReflectionMethod_constructor_error2.phpt39
-rw-r--r--ext/reflection/tests/ReflectionParameter_invalidMethodInConstructor.phpt21
-rw-r--r--ext/reflection/tests/ReflectionProperty_error.phpt50
-rw-r--r--ext/spl/spl_fixedarray.c9
-rw-r--r--ext/spl/tests/SplFixedArray__construct_param_array.phpt9
-rw-r--r--ext/spl/tests/SplFixedArray__construct_param_string.phpt9
-rw-r--r--ext/spl/tests/SplFixedArray_construct_param_SplFixedArray.phpt13
-rw-r--r--ext/spl/tests/fixedarray_005.phpt10
-rw-r--r--ext/spl/tests/fixedarray_009.phpt10
-rw-r--r--ext/spl/tests/fixedarray_015.phpt40
42 files changed, 589 insertions, 310 deletions
diff --git a/ext/fileinfo/fileinfo.c b/ext/fileinfo/fileinfo.c
index b4a556d57b..33c67d1ec1 100644
--- a/ext/fileinfo/fileinfo.c
+++ b/ext/fileinfo/fileinfo.c
@@ -301,8 +301,18 @@ PHP_FUNCTION(finfo_open)
php_fileinfo *finfo;
FILEINFO_DECLARE_INIT_OBJECT(object)
char resolved_path[MAXPATHLEN];
+ zend_error_handling zeh;
+ int rv;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "|lp", &options, &file, &file_len) == FAILURE) {
+ if (object) {
+ zend_replace_error_handling(EH_THROW, NULL, &zeh TSRMLS_CC);
+ rv = zend_parse_parameters(ZEND_NUM_ARGS(), "|lp", &options, &file, &file_len);
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+ } else {
+ rv = zend_parse_parameters(ZEND_NUM_ARGS(), "|lp", &options, &file, &file_len);
+ }
+
+ if (rv == FAILURE) {
FILEINFO_DESTROY_OBJECT(object);
RETURN_FALSE;
}
diff --git a/ext/intl/breakiterator/breakiterator_methods.cpp b/ext/intl/breakiterator/breakiterator_methods.cpp
index baab5a682d..02d228653a 100644
--- a/ext/intl/breakiterator/breakiterator_methods.cpp
+++ b/ext/intl/breakiterator/breakiterator_methods.cpp
@@ -162,12 +162,12 @@ U_CFUNC PHP_FUNCTION(breakiter_set_text)
BREAKITER_METHOD_FETCH_OBJECT;
ut = utext_openUTF8(ut, text->val, text->len, BREAKITER_ERROR_CODE_P(bio));
- INTL_CTOR_CHECK_STATUS(bio, "breakiter_set_text: error opening UText");
+ INTL_CTOR_CHECK_STATUS(bio, "breakiter_set_text: error opening UText", 0);
bio->biter->setText(ut, BREAKITER_ERROR_CODE(bio));
utext_close(ut); /* ICU shallow clones the UText */
INTL_CTOR_CHECK_STATUS(bio, "breakiter_set_text: error calling "
- "BreakIterator::setText()");
+ "BreakIterator::setText()", 0);
/* When ICU clones the UText, it does not copy the buffer, so we have to
* keep the string buffer around by holding a reference to its zval. This
diff --git a/ext/intl/calendar/gregoriancalendar_methods.cpp b/ext/intl/calendar/gregoriancalendar_methods.cpp
index 2ae5737227..69bae08e06 100644
--- a/ext/intl/calendar/gregoriancalendar_methods.cpp
+++ b/ext/intl/calendar/gregoriancalendar_methods.cpp
@@ -36,7 +36,7 @@ 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},
@@ -51,8 +51,8 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
// parameter number validation / variant determination
if (ZEND_NUM_ARGS() > 6 ||
zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) {
- intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
- "intlgregcal_create_instance: too many arguments", 0);
+ intl_error_set_ex(NULL, U_ILLEGAL_ARGUMENT_ERROR,
+ "intlgregcal_create_instance: too many arguments", 0, is_constructor);
Z_OBJ_P(return_value) = NULL;
return;
}
@@ -60,9 +60,9 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
variant > 0 && Z_TYPE(args[variant - 1]) == IS_NULL;
variant--) {}
if (variant == 4) {
- intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
+ intl_error_set_ex(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"intlgregcal_create_instance: no variant with 4 arguments "
- "(excluding trailing NULLs)", 0);
+ "(excluding trailing NULLs)", 0, is_constructor);
Z_OBJ_P(return_value) = NULL;
return;
}
@@ -71,8 +71,8 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
if (variant <= 2) {
if (zend_parse_parameters(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);
+ intl_error_set_ex(NULL, U_ILLEGAL_ARGUMENT_ERROR,
+ "intlgregcal_create_instance: bad arguments", 0, is_constructor);
Z_OBJ_P(return_value) = NULL;
return;
}
@@ -80,8 +80,8 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
if (variant > 2 && zend_parse_parameters(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,
- "intlgregcal_create_instance: bad arguments", 0);
+ intl_error_set_ex(NULL, U_ILLEGAL_ARGUMENT_ERROR,
+ "intlgregcal_create_instance: bad arguments", 0, is_constructor);
Z_OBJ_P(return_value) = NULL;
return;
}
@@ -104,8 +104,8 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
gcal = new GregorianCalendar(tz, Locale::createFromName(locale),
status);
if (U_FAILURE(status)) {
- intl_error_set(NULL, status, "intlgregcal_create_instance: error "
- "creating ICU GregorianCalendar from time zone and locale", 0);
+ intl_error_set_ex(NULL, status, "intlgregcal_create_instance: error "
+ "creating ICU GregorianCalendar from time zone and locale", 0, is_constructor);
if (gcal) {
delete gcal;
}
@@ -117,9 +117,9 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
// From date/time (3, 5 or 6 arguments)
for (int i = 0; i < variant; i++) {
if (largs[i] < INT32_MIN || largs[i] > INT32_MAX) {
- intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
+ intl_error_set_ex(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"intlgregcal_create_instance: at least one of the arguments"
- " has an absolute value that is too large", 0);
+ " has an absolute value that is too large", 0, is_constructor);
Z_OBJ_P(return_value) = NULL;
return;
}
@@ -137,8 +137,8 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
status);
}
if (U_FAILURE(status)) {
- intl_error_set(NULL, status, "intlgregcal_create_instance: error "
- "creating ICU GregorianCalendar from date", 0);
+ intl_error_set_ex(NULL, status, "intlgregcal_create_instance: error "
+ "creating ICU GregorianCalendar from date", 0, is_constructor);
if (gcal) {
delete gcal;
}
@@ -154,10 +154,10 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
strlen(tzinfo->name), US_INV);
#endif
if (tzstr.isBogus()) {
- intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
+ intl_error_set_ex(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"intlgregcal_create_instance: could not create UTF-8 string "
"from PHP's default timezone name (see date_default_timezone_get())",
- 0);
+ 0, is_constructor);
delete gcal;
Z_OBJ_P(return_value) = NULL;
return;
@@ -179,7 +179,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);
@@ -194,7 +194,7 @@ U_CFUNC PHP_METHOD(IntlGregorianCalendar, __construct)
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) {
zend_object_store_ctor_failed(Z_OBJ(orig_this));
diff --git a/ext/intl/collator/collator_create.c b/ext/intl/collator/collator_create.c
index b2058422c2..7631d76ff4 100644
--- a/ext/intl/collator/collator_create.c
+++ b/ext/intl/collator/collator_create.c
@@ -25,7 +25,7 @@
#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;
@@ -38,8 +38,8 @@ static void collator_ctor(INTERNAL_FUNCTION_PARAMETERS)
if( zend_parse_parameters( ZEND_NUM_ARGS(), "s",
&locale, &locale_len ) == FAILURE )
{
- intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
- "collator_create: unable to parse input params", 0 );
+ intl_error_set_ex( NULL, U_ILLEGAL_ARGUMENT_ERROR,
+ "collator_create: unable to parse input params", 0, is_constructor );
zval_dtor(return_value);
RETURN_NULL();
}
@@ -53,7 +53,7 @@ static void collator_ctor(INTERNAL_FUNCTION_PARAMETERS)
/* Open ICU collator. */
co->ucoll = ucol_open( locale, COLLATOR_ERROR_CODE_P( co ) );
- INTL_CTOR_CHECK_STATUS(co, "collator_create: unable to open ICU collator");
+ INTL_CTOR_CHECK_STATUS(co, "collator_create: unable to open ICU collator", is_constructor);
}
/* }}} */
@@ -63,7 +63,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);
}
/* }}} */
@@ -75,7 +75,7 @@ PHP_METHOD( Collator, __construct )
zval orig_this = *getThis();
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) {
zend_object_store_ctor_failed(Z_OBJ(orig_this));
diff --git a/ext/intl/converter/converter.c b/ext/intl/converter/converter.c
index 9bba427409..760d763b83 100644
--- a/ext/intl/converter/converter.c
+++ b/ext/intl/converter/converter.c
@@ -22,6 +22,7 @@
#include <unicode/ustring.h>
#include "../intl_error.h"
+#include "../intl_common.h"
typedef struct _php_converter_object {
UConverter *src, *dest;
@@ -556,11 +557,17 @@ 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);
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s!",
- &dest, &dest_len, &src, &src_len) == FAILURE) {
+ zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &zeh TSRMLS_CC);
+ rv = zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s!",
+ &dest, &dest_len, &src, &src_len);
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (rv == FAILURE) {
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"UConverter::__construct(): bad arguments", 0);
return;
diff --git a/ext/intl/dateformat/dateformat_create.cpp b/ext/intl/dateformat/dateformat_create.cpp
index f8cf77641f..31fcaeb7fc 100644
--- a/ext/intl/dateformat/dateformat_create.cpp
+++ b/ext/intl/dateformat/dateformat_create.cpp
@@ -36,7 +36,7 @@ extern "C" {
#include "dateformat_helpers.h"
/* {{{ */
-static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
+static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor)
{
zval *object;
@@ -64,8 +64,8 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
if (zend_parse_parameters(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: "
- "unable to parse input parameters", 0);
+ intl_error_set_ex( NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: "
+ "unable to parse input parameters", 0, is_constructor);
Z_OBJ_P(return_value) = NULL;
return;
}
@@ -79,6 +79,8 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
DATE_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK;
if (DATE_FORMAT_OBJECT(dfo) != NULL) {
+ /* This is __construct being called on an instance - it is not
+ a constructor. */
intl_errors_set(INTL_DATA_ERROR_P(dfo), U_ILLEGAL_ARGUMENT_ERROR,
"datefmt_create: cannot call constructor twice", 0);
return;
@@ -110,8 +112,8 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
pattern_str, pattern_str_len, &INTL_DATA_ERROR_CODE(dfo));
if (U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) {
/* object construction -> only set global error */
- intl_error_set(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create: "
- "error converting pattern to UTF-16", 0);
+ intl_error_set_ex(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create: "
+ "error converting pattern to UTF-16", 0, is_constructor);
goto error;
}
}
@@ -139,8 +141,8 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
df->adoptTimeZone(timezone);
}
} else {
- intl_error_set(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create: date "
- "formatter creation failed", 0);
+ intl_error_set_ex(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create: date "
+ "formatter creation failed", 0, is_constructor);
goto error;
}
@@ -175,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();
}
@@ -192,7 +194,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) {
zend_object_store_ctor_failed(Z_OBJ(orig_this));
diff --git a/ext/intl/formatter/formatter_main.c b/ext/intl/formatter/formatter_main.c
index 60db673ff2..c8ca65da27 100644
--- a/ext/intl/formatter/formatter_main.c
+++ b/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;
@@ -39,8 +39,8 @@ static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
if( zend_parse_parameters( ZEND_NUM_ARGS(), "sl|s",
&locale, &locale_len, &style, &pattern, &pattern_len ) == FAILURE )
{
- intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
- "numfmt_create: unable to parse input parameters", 0 );
+ intl_error_set_ex( NULL, U_ILLEGAL_ARGUMENT_ERROR,
+ "numfmt_create: unable to parse input parameters", 0, is_constructor );
Z_OBJ_P(return_value) = NULL;
return;
}
@@ -52,7 +52,7 @@ static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
/* Convert pattern (if specified) to UTF-16. */
if(pattern && pattern_len) {
intl_convert_utf8_to_utf16(&spattern, &spattern_len, pattern, pattern_len, &INTL_DATA_ERROR_CODE(nfo));
- INTL_CTOR_CHECK_STATUS(nfo, "numfmt_create: error converting pattern to UTF-16");
+ INTL_CTOR_CHECK_STATUS(nfo, "numfmt_create: error converting pattern to UTF-16", is_constructor);
}
if(locale_len == 0) {
@@ -66,7 +66,7 @@ static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
efree(spattern);
}
- INTL_CTOR_CHECK_STATUS(nfo, "numfmt_create: number formatter creation failed");
+ INTL_CTOR_CHECK_STATUS(nfo, "numfmt_create: number formatter creation failed", is_constructor);
}
/* }}} */
@@ -78,7 +78,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();
}
@@ -93,7 +93,7 @@ PHP_METHOD( NumberFormatter, __construct )
zval orig_this = *getThis();
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) {
zend_object_store_ctor_failed(Z_OBJ(orig_this));
diff --git a/ext/intl/intl_common.h b/ext/intl/intl_common.h
index a49794648d..61da2738d1 100644
--- a/ext/intl/intl_common.h
+++ b/ext/intl/intl_common.h
@@ -41,4 +41,6 @@
#define INTL_Z_STRVAL_P(str) (UChar*) Z_STRVAL_P(str)
#define INTL_Z_STRLEN_P(str) UCHARS( Z_STRLEN_P(str) )
+extern zend_class_entry *IntlException_ce_ptr;
+
#endif /* INTL_COMMON_H */
diff --git a/ext/intl/intl_data.h b/ext/intl/intl_data.h
index 6001aa1285..c49214ffcd 100644
--- a/ext/intl/intl_data.h
+++ b/ext/intl/intl_data.h
@@ -64,11 +64,11 @@ typedef struct _intl_data {
}
/* Check status, if error - destroy value and exit */
-#define INTL_CTOR_CHECK_STATUS(obj, msg) \
+#define INTL_CTOR_CHECK_STATUS(obj, msg, forceException) \
intl_error_set_code( NULL, INTL_DATA_ERROR_CODE((obj)) ); \
if( U_FAILURE( INTL_DATA_ERROR_CODE((obj)) ) ) \
{ \
- intl_errors_set_custom_msg( INTL_DATA_ERROR_P((obj)), msg, 0 ); \
+ intl_errors_set_custom_msg_ex( INTL_DATA_ERROR_P((obj)), msg, 0, forceException ); \
/* yes, this is ugly, but it alreay is */ \
if (return_value != getThis()) { \
zval_dtor(return_value); \
diff --git a/ext/intl/intl_error.c b/ext/intl/intl_error.c
index 28a2a244e2..8ea5e7b4cf 100644
--- a/ext/intl/intl_error.c
+++ b/ext/intl/intl_error.c
@@ -29,7 +29,7 @@
ZEND_EXTERN_MODULE_GLOBALS( intl )
-static zend_class_entry *IntlException_ce_ptr;
+zend_class_entry *IntlException_ce_ptr;
/* {{{ intl_error* intl_g_error_get()
* Return global error structure.
@@ -103,14 +103,25 @@ void intl_error_reset( intl_error* err )
*/
void intl_error_set_custom_msg( intl_error* err, char* msg, int copyMsg )
{
+ intl_error_set_custom_msg_ex( err, msg, copyMsg, 0 );
+}
+/* }}} */
+
+
+/* {{{ 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_ex( intl_error* err, char* msg, int copyMsg, int forceException )
+{
if( !msg )
return;
if( !err ) {
- if( INTL_G( error_level ) )
- php_error_docref( NULL, INTL_G( error_level ), "%s", msg );
- if( INTL_G( use_exceptions ) )
+ if ( forceException || INTL_G( use_exceptions ) ) {
zend_throw_exception_ex( IntlException_ce_ptr, 0, "%s", msg );
+ } else if( INTL_G( error_level ) ) {
+ php_error_docref( NULL, INTL_G( error_level ), "%s", msg );
+ }
}
if( !err && !( err = intl_g_error_get( ) ) )
return;
@@ -182,18 +193,38 @@ UErrorCode intl_error_get_code( intl_error* err )
*/
void intl_error_set( intl_error* err, UErrorCode code, char* msg, int copyMsg )
{
+ intl_error_set_ex( err, code, msg, copyMsg, 0 );
+}
+/* }}} */
+
+
+/* {{{ void intl_error_set( intl_error* err, UErrorCode code, char* msg, int copyMsg )
+ * Set error code and message.
+ */
+void intl_error_set_ex( intl_error* err, UErrorCode code, char* msg, int copyMsg, int forceException )
+{
intl_error_set_code( err, code );
- intl_error_set_custom_msg( err, msg, copyMsg );
+ intl_error_set_custom_msg_ex( err, msg, copyMsg, forceException );
}
/* }}} */
+
/* {{{ 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 )
{
+ intl_errors_set_ex( err, code, msg, copyMsg, 0 );
+}
+/* }}} */
+
+/* {{{ void intl_errors_set_ex( intl_error* err, UErrorCode code, char* msg, int copyMsg )
+ * Set error code and message.
+ */
+void intl_errors_set_ex( intl_error* err, UErrorCode code, char* msg, int copyMsg, int forceException )
+{
intl_errors_set_code( err, code );
- intl_errors_set_custom_msg( err, msg, copyMsg );
+ intl_errors_set_custom_msg_ex( err, msg, copyMsg, forceException );
}
/* }}} */
@@ -212,13 +243,23 @@ void intl_errors_reset( intl_error* err )
*/
void intl_errors_set_custom_msg( intl_error* err, char* msg, int copyMsg )
{
+ intl_errors_set_custom_msg_ex( err, msg, copyMsg, 0 );
+}
+/* }}} */
+
+
+/* {{{ void intl_errors_set_custom_msg( intl_error* err, char* msg, int copyMsg )
+ */
+void intl_errors_set_custom_msg_ex( intl_error* err, char* msg, int copyMsg, int forceException )
+{
if(err) {
- intl_error_set_custom_msg( err, msg, copyMsg );
+ intl_error_set_custom_msg_ex( err, msg, copyMsg, forceException );
}
- intl_error_set_custom_msg( NULL, msg, copyMsg );
+ intl_error_set_custom_msg_ex( NULL, msg, copyMsg, forceException );
}
/* }}} */
+
/* {{{ intl_errors_set_code( intl_error* err, UErrorCode err_code )
*/
void intl_errors_set_code( intl_error* err, UErrorCode err_code )
diff --git a/ext/intl/intl_error.h b/ext/intl/intl_error.h
index 02d62f0299..4c9349b281 100644
--- a/ext/intl/intl_error.h
+++ b/ext/intl/intl_error.h
@@ -36,15 +36,21 @@ 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_custom_msg_ex( intl_error* err, char* msg, int copyMsg, int forceException );
void intl_error_set( intl_error* err, UErrorCode code, char* msg, int copyMsg );
+void intl_error_set_ex( intl_error* err, UErrorCode code, char* msg, int copyMsg, int forceException );
+
+
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_ex( intl_error* err, char* msg, int copyMsg, int forceException );
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_ex( intl_error* err, UErrorCode code, char* msg, int copyMsg, int forceException );
// Other error helpers
smart_str intl_parse_error_to_string( UParseError* pe );
diff --git a/ext/intl/msgformat/msgformat.c b/ext/intl/msgformat/msgformat.c
index 707b38bd95..34923f92a5 100644
--- a/ext/intl/msgformat/msgformat.c
+++ b/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;
@@ -42,8 +42,8 @@ static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
if( zend_parse_parameters( ZEND_NUM_ARGS(), "ss",
&locale, &locale_len, &pattern, &pattern_len ) == FAILURE )
{
- intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
- "msgfmt_create: unable to parse input parameters", 0 );
+ intl_error_set_ex( NULL, U_ILLEGAL_ARGUMENT_ERROR,
+ "msgfmt_create: unable to parse input parameters", 0, is_constructor );
Z_OBJ_P(return_value) = NULL;
return;
}
@@ -54,7 +54,7 @@ static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
/* Convert pattern (if specified) to UTF-16. */
if(pattern && pattern_len) {
intl_convert_utf8_to_utf16(&spattern, &spattern_len, pattern, pattern_len, &INTL_DATA_ERROR_CODE(mfo));
- INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: error converting pattern to UTF-16");
+ INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: error converting pattern to UTF-16", is_constructor);
} else {
spattern_len = 0;
spattern = NULL;
@@ -66,7 +66,7 @@ static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
#ifdef MSG_FORMAT_QUOTE_APOS
if(msgformat_fix_quotes(&spattern, &spattern_len, &INTL_DATA_ERROR_CODE(mfo)) != SUCCESS) {
- INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: error converting pattern to quote-friendly format");
+ INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: error converting pattern to quote-friendly format", is_constructor);
}
#endif
@@ -84,7 +84,7 @@ static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
efree(spattern);
}
- INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: message formatter creation failed");
+ INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: message formatter creation failed", is_constructor);
}
/* }}} */
@@ -96,7 +96,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();
}
@@ -111,7 +111,7 @@ PHP_METHOD( MessageFormatter, __construct )
zval orig_this = *getThis();
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) {
zend_object_store_ctor_failed(Z_OBJ(orig_this));
diff --git a/ext/intl/msgformat/msgformat_class.c b/ext/intl/msgformat/msgformat_class.c
index 8d464c6ca4..1296d087e1 100644
--- a/ext/intl/msgformat/msgformat_class.c
+++ b/ext/intl/msgformat/msgformat_class.c
@@ -87,10 +87,10 @@ zend_object *MessageFormatter_object_clone(zval *object)
if (U_FAILURE(INTL_DATA_ERROR_CODE(mfo))) {
intl_errors_set(INTL_DATA_ERROR_P(mfo), INTL_DATA_ERROR_CODE(mfo),
"Failed to clone MessageFormatter object", 0);
- zend_throw_exception_ex(NULL, 0, "Failed to clone MessageFormatter object");
+ zend_throw_exception_ex(IntlException_ce_ptr, 0, "Failed to clone MessageFormatter object");
}
} else {
- zend_throw_exception_ex(NULL, 0, "Cannot clone unconstructed MessageFormatter");
+ zend_throw_exception_ex(IntlException_ce_ptr, 0, "Cannot clone unconstructed MessageFormatter");
}
return new_obj;
}
diff --git a/ext/intl/resourcebundle/resourcebundle_class.c b/ext/intl/resourcebundle/resourcebundle_class.c
index b8d27c940a..60800fe1a9 100644
--- a/ext/intl/resourcebundle/resourcebundle_class.c
+++ b/ext/intl/resourcebundle/resourcebundle_class.c
@@ -74,7 +74,7 @@ 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;
@@ -90,8 +90,8 @@ static void resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS)
if( zend_parse_parameters( ZEND_NUM_ARGS(), "s!s!|b",
&locale, &locale_len, &bundlename, &bundlename_len, &fallback ) == FAILURE )
{
- intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
- "resourcebundle_ctor: unable to parse input parameters", 0 );
+ intl_error_set_ex( NULL, U_ILLEGAL_ARGUMENT_ERROR,
+ "resourcebundle_ctor: unable to parse input parameters", 0, is_constructor );
Z_OBJ_P(return_value) = NULL;
return;
}
@@ -108,7 +108,7 @@ static void resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS)
rb->me = ures_openDirect(bundlename, locale, &INTL_DATA_ERROR_CODE(rb));
}
- INTL_CTOR_CHECK_STATUS(rb, "resourcebundle_ctor: Cannot load libICU resource bundle");
+ INTL_CTOR_CHECK_STATUS(rb, "resourcebundle_ctor: Cannot load libICU resource bundle", is_constructor);
if (!fallback && (INTL_DATA_ERROR_CODE(rb) == U_USING_FALLBACK_WARNING ||
INTL_DATA_ERROR_CODE(rb) == U_USING_DEFAULT_WARNING)) {
@@ -119,7 +119,7 @@ static void resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS)
bundlename ? bundlename : "(default data)", locale,
ures_getLocaleByType(
rb->me, ULOC_ACTUAL_LOCALE, &INTL_DATA_ERROR_CODE(rb)));
- intl_errors_set_custom_msg(INTL_DATA_ERROR_P(rb), pbuf, 1);
+ intl_errors_set_custom_msg_ex(INTL_DATA_ERROR_P(rb), pbuf, 1, is_constructor);
efree(pbuf);
Z_OBJ_P(return_value) = NULL;
}
@@ -142,7 +142,7 @@ PHP_METHOD( ResourceBundle, __construct )
zval orig_this = *getThis();
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) {
zend_object_store_ctor_failed(Z_OBJ(orig_this));
@@ -157,7 +157,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();
}
diff --git a/ext/intl/spoofchecker/spoofchecker_create.c b/ext/intl/spoofchecker/spoofchecker_create.c
index d797015cf8..b56c840961 100644
--- a/ext/intl/spoofchecker/spoofchecker_create.c
+++ b/ext/intl/spoofchecker/spoofchecker_create.c
@@ -38,7 +38,7 @@ PHP_METHOD(Spoofchecker, __construct)
SPOOFCHECKER_METHOD_FETCH_OBJECT_NO_CHECK;
co->uspoof = uspoof_open(SPOOFCHECKER_ERROR_CODE_P(co));
- INTL_CTOR_CHECK_STATUS(co, "spoofchecker: unable to open ICU Spoof Checker");
+ INTL_CTOR_CHECK_STATUS(co, "spoofchecker: unable to open ICU Spoof Checker", 1);
/* Single-script enforcement is on by default. This fails for languages
like Japanese that legally use multiple scripts within a single word,
diff --git a/ext/intl/tests/bug62017.phpt b/ext/intl/tests/bug62017.phpt
index 50aeae4806..e5c216c1e2 100644
--- a/ext/intl/tests/bug62017.phpt
+++ b/ext/intl/tests/bug62017.phpt
@@ -10,13 +10,15 @@ ini_set('intl.error_level', E_WARNING);
var_dump(
datefmt_create('', IntlDateFormatter::NONE, IntlDateFormatter::NONE, "\xFF",
IntlDateFormatter::GREGORIAN, 'a'));
-var_dump(
+try {
new IntlDateFormatter('', IntlDateFormatter::NONE, IntlDateFormatter::NONE, "Europe/Lisbon",
- IntlDateFormatter::GREGORIAN, "\x80"));
+ IntlDateFormatter::GREGORIAN, "\x80");
+}
+catch(IntlException $ie) {
+ echo $ie->getMessage().PHP_EOL;
+}
--EXPECTF--
Warning: datefmt_create(): datefmt_create: Time zone identifier given is not a valid UTF-8 string in %s on line %d
NULL
-
-Warning: IntlDateFormatter::__construct(): datefmt_create: error converting pattern to UTF-16 in %s on line %d
-NULL
+datefmt_create: error converting pattern to UTF-16
diff --git a/ext/intl/tests/formatter_fail.phpt b/ext/intl/tests/formatter_fail.phpt
index 295f011008..c45b113bdb 100644
--- a/ext/intl/tests/formatter_fail.phpt
+++ b/ext/intl/tests/formatter_fail.phpt
@@ -12,16 +12,23 @@ function err($fmt) {
}
function crt($t, $l, $s) {
- switch(true) {
- case $t == "O":
- return new NumberFormatter($l, $s);
- break;
- case $t == "C":
- return NumberFormatter::create($l, $s);
- break;
- case $t == "P":
- return numfmt_create($l, $s);
- break;
+ try {
+ $fmt = null;
+ switch(true) {
+ case $t == "O":
+ $fmt = new NumberFormatter($l, $s);
+ break;
+ case $t == "C":
+ $fmt = NumberFormatter::create($l, $s);
+ break;
+ case $t == "P":
+ $fmt = numfmt_create($l, $s);
+ break;
+ }
+ err($fmt);
+ }
+ catch(IntlException $ie) {
+ echo "IE: ".$ie->getMessage().PHP_EOL;
}
}
@@ -33,8 +40,13 @@ $args = array(
array("en_US", NumberFormatter::PATTERN_RULEBASED),
);
-$fmt = new NumberFormatter();
-err($fmt);
+try {
+ $fmt = new NumberFormatter();
+}
+catch(IntlException $ie) {
+ echo $ie->getMessage().PHP_EOL;
+}
+
$fmt = numfmt_create();
err($fmt);
$fmt = NumberFormatter::create();
@@ -42,11 +54,8 @@ err($fmt);
foreach($args as $arg) {
$fmt = crt("O", $arg[0], $arg[1]);
- err($fmt);
$fmt = crt("C", $arg[0], $arg[1]);
- err($fmt);
$fmt = crt("P", $arg[0], $arg[1]);
- err($fmt);
}
?>
@@ -70,10 +79,10 @@ Warning: NumberFormatter::create() expects parameter 1 to be string, array given
'numfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
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'
-'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'
-'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'
+IE: numfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR
+IE: numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR
+IE: numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR
+IE: numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR
+IE: numfmt_create: number formatter creation failed: U_MEMORY_ALLOCATION_ERROR
+IE: numfmt_create: number formatter creation failed: U_MEMORY_ALLOCATION_ERROR
+IE: numfmt_create: number formatter creation failed: U_MEMORY_ALLOCATION_ERROR
diff --git a/ext/intl/tests/formatter_format.phpt b/ext/intl/tests/formatter_format.phpt
index 334ef49567..0fa88681d9 100644
--- a/ext/intl/tests/formatter_format.phpt
+++ b/ext/intl/tests/formatter_format.phpt
@@ -50,7 +50,14 @@ function ut_main()
$str_res .= "\nLocale is: $locale\n";
foreach( $styles as $style => $pattern )
{
- $fmt = ut_nfmt_create( $locale, $style, $pattern );
+ try {
+ $fmt = ut_nfmt_create( $locale, $style, $pattern );
+ }
+ catch (IntlException $ie) {
+ //$str_res .= "IE:".$ie->getMessage()."\n";
+ $str_res .= "Bad formatter!\n";
+ continue;
+ }
if(!$fmt) {
$str_res .= "Bad formatter!\n";
diff --git a/ext/intl/tests/gregoriancalendar___construct_error.phpt b/ext/intl/tests/gregoriancalendar___construct_error.phpt
index 45229cf000..a28fa715e4 100644
--- a/ext/intl/tests/gregoriancalendar___construct_error.phpt
+++ b/ext/intl/tests/gregoriancalendar___construct_error.phpt
@@ -11,8 +11,18 @@ ini_set("intl.error_level", E_WARNING);
var_dump(intlgregcal_create_instance(1,2,3,4,5,6,7));
var_dump(intlgregcal_create_instance(1,2,3,4,5,6,7,8));
var_dump(intlgregcal_create_instance(1,2,3,4));
-var_dump(new IntlGregorianCalendar(1,2,NULL,4));
-var_dump(new IntlGregorianCalendar(1,2,3,4,NULL,array()));
+try {
+ new IntlGregorianCalendar(1,2,NULL,4);
+}
+catch (IntlException $ie) {
+ echo "IE: ".$ie->getMessage().PHP_EOL;
+}
+try {
+ new IntlGregorianCalendar(1,2,3,4,NULL,array());
+}
+catch (IntlException $ie) {
+ echo "IE: ".$ie->getMessage().PHP_EOL;
+}
--EXPECTF--
@@ -26,10 +36,6 @@ NULL
Warning: intlgregcal_create_instance(): intlgregcal_create_instance: no variant with 4 arguments (excluding trailing NULLs) in %s on line %d
NULL
-Warning: IntlGregorianCalendar::__construct(): intlgregcal_create_instance: no variant with 4 arguments (excluding trailing NULLs) in %s on line %d
-NULL
-
+IE: IntlGregorianCalendar::__construct(): intlgregcal_create_instance: no variant with 4 arguments (excluding trailing NULLs)
Warning: IntlGregorianCalendar::__construct() expects parameter 6 to be integer, array given in %s on line %d
-
-Warning: IntlGregorianCalendar::__construct(): intlgregcal_create_instance: bad arguments in %s on line %d
-NULL
+IE: IntlGregorianCalendar::__construct(): intlgregcal_create_instance: bad arguments
diff --git a/ext/intl/tests/msgfmt_fail.phpt b/ext/intl/tests/msgfmt_fail.phpt
index bffb71c56d..4b60b35abc 100644
--- a/ext/intl/tests/msgfmt_fail.phpt
+++ b/ext/intl/tests/msgfmt_fail.phpt
@@ -13,16 +13,24 @@ function err($fmt) {
}
function crt($t, $l, $s) {
- switch(true) {
- case $t == "O":
- return new MessageFormatter($l, $s);
- break;
- case $t == "C":
- return MessageFormatter::create($l, $s);
- break;
- case $t == "P":
- return msgfmt_create($l, $s);
- break;
+
+ try {
+ $fmt = null;
+ switch(true) {
+ case $t == "O":
+ $fmt = new MessageFormatter($l, $s);
+ break;
+ case $t == "C":
+ $fmt = MessageFormatter::create($l, $s);
+ break;
+ case $t == "P":
+ $fmt = msgfmt_create($l, $s);
+ break;
+ }
+ err($fmt);
+ }
+ catch (IntlException $ie) {
+ echo "IE: ".$ie->getMessage().PHP_EOL;
}
}
@@ -35,32 +43,36 @@ $args = array(
array("en_US", "\xD0"),
);
-$fmt = new MessageFormatter();
-err($fmt);
+try {
+ $fmt = new MessageFormatter();
+}
+catch(IntlException $ie) {
+ echo "IE: ".$ie->getMessage().PHP_EOL;
+}
$fmt = msgfmt_create();
err($fmt);
$fmt = MessageFormatter::create();
-err($fmt);
-$fmt = new MessageFormatter('en');
-err($fmt);
+err($fmt);
+try {
+ $fmt = new MessageFormatter('en');
+}
+catch(IntlException $ie) {
+ echo "IE: ".$ie->getMessage().PHP_EOL;
+}
$fmt = msgfmt_create('en');
err($fmt);
$fmt = MessageFormatter::create('en');
err($fmt);
foreach($args as $arg) {
- $fmt = crt("O", $arg[0], $arg[1]);
- err($fmt);
- $fmt = crt("C", $arg[0], $arg[1]);
- err($fmt);
- $fmt = crt("P", $arg[0], $arg[1]);
- err($fmt);
+ crt("O", $arg[0], $arg[1]);
+ crt("C", $arg[0], $arg[1]);
+ crt("P", $arg[0], $arg[1]);
}
?>
--EXPECTF--
-Warning: MessageFormatter::__construct() expects exactly 2 parameters, 0 given in %s on line %d
-'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
+IE: msgfmt_create: unable to parse input parameters
Warning: msgfmt_create() expects exactly 2 parameters, 0 given in %s on line %d
'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
@@ -68,8 +80,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'
-Warning: MessageFormatter::__construct() expects exactly 2 parameters, 1 given in %s on line %d
-'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
+IE: msgfmt_create: unable to parse input parameters
Warning: msgfmt_create() expects exactly 2 parameters, 1 given in %s on line %d
'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
diff --git a/ext/intl/tests/msgfmt_parse.phpt b/ext/intl/tests/msgfmt_parse.phpt
index b9ec36374b..2eaf630010 100644
--- a/ext/intl/tests/msgfmt_parse.phpt
+++ b/ext/intl/tests/msgfmt_parse.phpt
@@ -36,9 +36,15 @@ function ut_main()
foreach( $locales as $locale => $pattern )
{
$str_res .= "\nLocale is: $locale\n";
- $fmt = ut_msgfmt_create( $locale, $pattern );
- if(!$fmt) {
- $str_res .= dump(intl_get_error_message())."\n";
+ try {
+ $fmt = ut_msgfmt_create( $locale, $pattern );
+ if(!$fmt) {
+ $str_res .= dump(intl_get_error_message())."\n";
+ continue;
+ }
+ }
+ catch (\IntlException $ie) {
+ $str_res .= "IE: ".$ie->getMessage().PHP_EOL;
continue;
}
$str_res .= dump( ut_msgfmt_parse( $fmt, $results[$locale] ) ) . "\n";
@@ -103,7 +109,7 @@ array (
)
Locale is: root
-'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
+IE: msgfmt_create: message formatter creation failed
Locale is: fr
array (
diff --git a/ext/intl/tests/resourcebundle_create.phpt b/ext/intl/tests/resourcebundle_create.phpt
index 2bf4f556a8..99492a698b 100644
--- a/ext/intl/tests/resourcebundle_create.phpt
+++ b/ext/intl/tests/resourcebundle_create.phpt
@@ -14,6 +14,7 @@ function ut_main() {
$str_res .= debug( $r1 );
$str_res .= print_r( $r1['teststring'], true)."\n";
+
// non-root one
$r1 = ut_resourcebundle_create( 'es', BUNDLE );
$str_res .= debug( $r1 );
@@ -24,14 +25,22 @@ function ut_main() {
$str_res .= debug( $r1 );
$str_res .= print_r( $r1['testsring'], true);
- // fall out
- $r2 = ut_resourcebundle_create( 'en_US', BUNDLE, false );
- $str_res .= debug( $r2 );
+ try {
+ // fall out
+ $r2 = ut_resourcebundle_create( 'en_US', BUNDLE, false );
+ }
+ catch (\IntlException $ie) {
+ $str_res .= "ie: ".$ie->getMessage().PHP_EOL;
+ }
+
+ try {
+ // missing
+ $r3 = ut_resourcebundle_create( 'en_US', 'nonexisting' );
+ }
+ catch (\IntlException $ie) {
+ $str_res .= "ie: ".$ie->getMessage().PHP_EOL;
+ }
- // missing
- $r3 = ut_resourcebundle_create( 'en_US', 'nonexisting' );
- $str_res .= debug( $r3 );
-
return $str_res;
}
@@ -56,7 +65,5 @@ ResourceBundle Object
)
-127: U_USING_DEFAULT_WARNING
-NULL
- 2: resourcebundle_ctor: Cannot load libICU resource bundle: U_MISSING_RESOURCE_ERROR
-NULL
- 2: resourcebundle_ctor: Cannot load libICU resource bundle: U_MISSING_RESOURCE_ERROR
+ie: resourcebundle_ctor: Cannot load libICU resource bundle
+ie: resourcebundle_ctor: Cannot load libICU resource bundle
diff --git a/ext/intl/transliterator/transliterator_methods.c b/ext/intl/transliterator/transliterator_methods.c
index d8b030a6d1..7be1412b13 100644
--- a/ext/intl/transliterator/transliterator_methods.c
+++ b/ext/intl/transliterator/transliterator_methods.c
@@ -169,7 +169,7 @@ PHP_FUNCTION( transliterator_create_from_rules )
str_rules, str_rules_len, TRANSLITERATOR_ERROR_CODE_P( to ) );
/* (I'm not a big fan of non-obvious flow control macros ).
* This one checks the error value, destroys object and returns false */
- INTL_CTOR_CHECK_STATUS( to, "String conversion of rules to UTF-16 failed" );
+ INTL_CTOR_CHECK_STATUS( to, "String conversion of rules to UTF-16 failed", 0 );
/* Open ICU Transliterator. */
utrans = utrans_openU( id, ( sizeof( id ) - 1 ) / ( sizeof( *id ) ), (UTransDirection ) direction,
@@ -197,7 +197,7 @@ PHP_FUNCTION( transliterator_create_from_rules )
}
transliterator_object_construct( object, utrans, TRANSLITERATOR_ERROR_CODE_P( to ) );
/* no need to close the transliterator manually on construction error */
- INTL_CTOR_CHECK_STATUS( to, "transliterator_create_from_rules: internal constructor call failed" );
+ INTL_CTOR_CHECK_STATUS( to, "transliterator_create_from_rules: internal constructor call failed", 0 );
}
/* }}} */
@@ -228,10 +228,10 @@ PHP_FUNCTION( transliterator_create_inverse )
utrans = utrans_openInverse( to_orig->utrans, TRANSLITERATOR_ERROR_CODE_P( to ) );
INTL_CTOR_CHECK_STATUS( to, "transliterator_create_inverse: could not create "
- "inverse ICU transliterator" );
+ "inverse ICU transliterator", 0 );
transliterator_object_construct( object, utrans, TRANSLITERATOR_ERROR_CODE_P( to ) );
/* no need to close the transliterator manually on construction error */
- INTL_CTOR_CHECK_STATUS( to, "transliterator_create: internal constructor call failed" );
+ INTL_CTOR_CHECK_STATUS( to, "transliterator_create: internal constructor call failed", 0 );
}
/* }}} */
diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c
index de9a6abbdc..1796435c5f 100644
--- a/ext/pdo/pdo_dbh.c
+++ b/ext/pdo/pdo_dbh.c
@@ -208,9 +208,15 @@ static PHP_METHOD(PDO, dbh_constructor)
zval *options = NULL;
char alt_dsn[512];
int call_factory = 1;
+ zend_error_handling zeh;
+ int rv;
- if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "s|s!s!a!", &data_source, &data_source_len,
- &username, &usernamelen, &password, &passwordlen, &options)) {
+ zend_replace_error_handling(EH_THROW, pdo_exception_ce, &zeh TSRMLS_CC);
+ rv = zend_parse_parameters(ZEND_NUM_ARGS(), "s|s!s!a!", &data_source, &data_source_len,
+ &username, &usernamelen, &password, &passwordlen, &options);
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (FAILURE == rv) {
ZEND_CTOR_MAKE_NULL();
return;
}
diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c
index c6ebc37ec2..ace865899e 100644
--- a/ext/pdo/pdo_stmt.c
+++ b/ext/pdo/pdo_stmt.c
@@ -113,9 +113,10 @@ ZEND_END_ARG_INFO()
RETURN_FALSE; \
} \
+//The class is called PDORow in userland, it is called PDOStatement in the manual.
static PHP_FUNCTION(dbstmt_constructor) /* {{{ */
{
- php_error_docref(NULL, E_ERROR, "You should not create a PDOStatement manually");
+ zend_throw_exception_ex(php_pdo_get_exception(), 0, "You may not create a PDORow manually");
}
/* }}} */
@@ -2640,6 +2641,7 @@ static union _zend_function *row_get_ctor(zend_object *object)
ctor.type = ZEND_INTERNAL_FUNCTION;
ctor.function_name = zend_string_init("__construct", sizeof("__construct") - 1, 0);
ctor.scope = pdo_row_ce;
+ //The class is called PDORow in userland, it is called PDOStatement in the manual.
ctor.handler = ZEND_FN(dbstmt_constructor);
ctor.fn_flags = ZEND_ACC_PUBLIC;
diff --git a/ext/pdo/tests/pdo_036.phpt b/ext/pdo/tests/pdo_036.phpt
index 55c88762ba..16a1597f36 100644
--- a/ext/pdo/tests/pdo_036.phpt
+++ b/ext/pdo/tests/pdo_036.phpt
@@ -7,17 +7,29 @@ Testing PDORow and PDOStatement instances with Reflection
$instance = new reflectionclass('pdostatement');
$x = $instance->newInstance();
-var_dump($x);
-$instance = new reflectionclass('pdorow');
-$x = $instance->newInstance();
-var_dump($x);
+if ($x instanceof pdostatement) {
+ echo "Ok".PHP_EOL;
+}
+else {
+ echo "Failed to create instance of pdostatment";
+}
-?>
---EXPECTF--
-object(PDOStatement)#%d (1) {
- [%u|b%"queryString"]=>
- NULL
+try {
+ $instance = new reflectionclass('pdorow');
+ $x = $instance->newInstance();
+ echo "Failed to throw exception: ".var_export($x, true);
+}
+catch(PDOException $pe) {
+ if ($pe->getMessage() != "You may not create a PDORow manually") {
+ echo "PDOException has wrong message.";
+ }
+ else {
+ echo "Ok".PHP_EOL;
+ }
}
-Fatal error: PDORow::__construct(): You should not create a PDOStatement manually in %spdo_036.php on line %d
+?>
+--EXPECTF--
+Ok
+Ok
diff --git a/ext/pdo/tests/pdorow.phpt b/ext/pdo/tests/pdorow.phpt
index bcfd8ff229..fca40a1ee1 100644
--- a/ext/pdo/tests/pdorow.phpt
+++ b/ext/pdo/tests/pdorow.phpt
@@ -5,8 +5,22 @@ Trying instantiate a PDORow object manually
--FILE--
<?php
-new PDORow;
+try {
+ $instance = new PDORow;
+ echo "Failed to throw exception.".var_export($instance, true);
+}
+catch(PDOException $pe) {
+ if ($pe->getMessage() != "You may not create a PDORow manually") {
+ echo "PDOException has wrong message.";
+ }
+ else {
+ echo "Ok".PHP_EOL;
+ }
+}
+catch(\Exception $e) {
+ echo "Exception throw was not of type PDOException instead was ".get_class($e).PHP_EOL;
+}
?>
--EXPECTF--
-Fatal error: PDORow::__construct(): You should not create a PDOStatement manually in %s on line %d
+Ok
diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c
index e276613209..982a67ba8a 100644
--- a/ext/phar/phar_object.c
+++ b/ext/phar/phar_object.c
@@ -1130,17 +1130,26 @@ 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) {
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|ls!l", &fname, &fname_len, &flags, &alias, &alias_len, &format) == FAILURE) {
+ 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) {
return;
}
} else {
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|ls!", &fname, &fname_len, &flags, &alias, &alias_len) == FAILURE) {
+ 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
return;
}
}
@@ -4350,8 +4359,14 @@ PHP_METHOD(PharFileInfo, __construct)
phar_entry_info *entry_info;
phar_archive_data *phar_data;
zval *zobj = getThis(), arg1;
+ zend_error_handling zeh;
+ int rv;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &fname, &fname_len) == FAILURE) {
+ 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) {
return;
}
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index e78410ec71..e7aed4da8e 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -1577,6 +1577,8 @@ ZEND_METHOD(reflection_function, __construct)
zend_function *fptr;
char *name_str;
size_t name_len;
+ int rv;
+ zend_error_handling zeh;
object = getThis();
intern = Z_REFLECTION_P(object);
@@ -1587,27 +1589,32 @@ ZEND_METHOD(reflection_function, __construct)
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "O", &closure, zend_ce_closure) == SUCCESS) {
fptr = (zend_function*)zend_get_closure_method_def(closure);
Z_ADDREF_P(closure);
- } else if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name_str, &name_len) == 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) {
+ } 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;
+ }
efree(lcname);
- zend_throw_exception_ex(reflection_exception_ptr, 0,
- "Function %s() does not exist", name_str);
+ } else {
+ //Exception has been thrown.
return;
}
- efree(lcname);
- } else {
- return;
}
ZVAL_STR_COPY(&name, fptr->common.function_name);
@@ -2129,10 +2136,14 @@ 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);
return;
}
+ zend_restore_error_handling(&zeh TSRMLS_CC);
object = getThis();
intern = Z_REFLECTION_P(object);
@@ -2713,7 +2724,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) {
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &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) {
return;
}
if ((tmp = strstr(name_str, "::")) == NULL) {
@@ -4786,7 +4803,14 @@ ZEND_METHOD(reflection_property, __construct)
zend_property_info *property_info = NULL;
property_reference *reference;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "zs", &classname, &name_str, &name_len) == FAILURE) {
+ 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) {
return;
}
@@ -5181,9 +5205,15 @@ 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)
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name_str, &name_len) == FAILURE) {
+ 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) {
return;
}
@@ -5550,8 +5580,14 @@ 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 (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name_str, &name_len) == FAILURE) {
+ if (rv == FAILURE) {
return;
}
diff --git a/ext/reflection/tests/ReflectionExtension_constructor_error.phpt b/ext/reflection/tests/ReflectionExtension_constructor_error.phpt
index 9eae206c50..f731ab51cc 100644
--- a/ext/reflection/tests/ReflectionExtension_constructor_error.phpt
+++ b/ext/reflection/tests/ReflectionExtension_constructor_error.phpt
@@ -5,12 +5,32 @@ Gerrit "Remi" te Sligte <remi@wolerized.com>
Leon Luijkx <leon@phpgg.nl>
--FILE--
<?php
-$obj = new ReflectionExtension();
-$test = $obj instanceof ReflectionExtension;
-var_dump($test);
+try {
+ $obj = new ReflectionExtension();
+}
+catch(ReflectionException $re) {
+ echo "Ok - ".$re->getMessage().PHP_EOL;
+}
+
+try {
+ $obj = new ReflectionExtension('foo', 'bar');
+}
+catch(ReflectionException $re) {
+ echo "Ok - ".$re->getMessage().PHP_EOL;
+}
+
+try {
+ $obj = new ReflectionExtension([]);
+}
+catch(ReflectionException $re) {
+ echo "Ok - ".$re->getMessage().PHP_EOL;
+}
+
+
?>
==DONE==
--EXPECTF--
-Warning: ReflectionExtension::__construct() expects exactly %d parameter, %d given in %s.php on line %d
-bool(true)
+Ok - ReflectionExtension::__construct() expects exactly %d parameter, %d given
+Ok - ReflectionExtension::__construct() expects exactly %d parameter, %d given
+Ok - ReflectionExtension::__construct() expects parameter 1 to be string, array given
==DONE==
diff --git a/ext/reflection/tests/ReflectionFunction_construct.001.phpt b/ext/reflection/tests/ReflectionFunction_construct.001.phpt
index c8e0a17a9d..90259ac997 100644
--- a/ext/reflection/tests/ReflectionFunction_construct.001.phpt
+++ b/ext/reflection/tests/ReflectionFunction_construct.001.phpt
@@ -6,18 +6,41 @@ Steve Seear <stevseea@php.net>
--FILE--
<?php
-$a = new ReflectionFunction(array(1, 2, 3));
+try {
+ $a = new ReflectionFunction(array(1, 2, 3));
+ echo "exception not thrown.".PHP_EOL;
+}
+catch(ReflectionException $re) {
+ echo "Ok - ".$re->getMessage().PHP_EOL;
+}
try {
$a = new ReflectionFunction('nonExistentFunction');
} catch (Exception $e) {
- echo $e->getMessage();
+ echo $e->getMessage().PHP_EOL;
+}
+try {
+ $a = new ReflectionFunction();
+}
+catch(ReflectionException $re) {
+ echo "Ok - ".$re->getMessage().PHP_EOL;
+}
+try {
+ $a = new ReflectionFunction(1, 2);
+}
+catch(ReflectionException $re) {
+ echo "Ok - ".$re->getMessage().PHP_EOL;
+}
+try {
+ $a = new ReflectionFunction([]);
}
-$a = new ReflectionFunction();
-$a = new ReflectionFunction(1, 2);
+catch(ReflectionException $re) {
+ echo "Ok - ".$re->getMessage().PHP_EOL;
+}
+
?>
--EXPECTF--
-Warning: ReflectionFunction::__construct() expects parameter 1 to be string, array given in %s on line %d
+Ok - ReflectionFunction::__construct() expects parameter 1 to be string, array given
Function nonExistentFunction() does not exist
-Warning: ReflectionFunction::__construct() expects exactly 1 parameter, 0 given in %s on line %d
-
-Warning: ReflectionFunction::__construct() expects exactly 1 parameter, 2 given in %s on line %d
+Ok - ReflectionFunction::__construct() expects exactly 1 parameter, 0 given
+Ok - ReflectionFunction::__construct() expects exactly 1 parameter, 2 given
+Ok - ReflectionFunction::__construct() expects parameter 1 to be string, array given
diff --git a/ext/reflection/tests/ReflectionMethod_006.phpt b/ext/reflection/tests/ReflectionMethod_006.phpt
index a5164190ca..0b8228989c 100644
--- a/ext/reflection/tests/ReflectionMethod_006.phpt
+++ b/ext/reflection/tests/ReflectionMethod_006.phpt
@@ -6,8 +6,18 @@ Steve Seear <stevseea@php.net>
--FILE--
<?php
-var_dump(new ReflectionMethod());
-var_dump(new ReflectionMethod('a', 'b', 'c'));
+try {
+ new ReflectionMethod();
+}
+catch(ReflectionException $re) {
+ echo "Ok - ".$re->getMessage().PHP_EOL;
+}
+try {
+ new ReflectionMethod('a', 'b', 'c');
+}
+catch(ReflectionException $re) {
+ echo "Ok - ".$re->getMessage().PHP_EOL;
+}
class C {
public function f() {}
@@ -35,21 +45,8 @@ var_dump($rm->getName(1));
?>
--EXPECTF--
-Warning: ReflectionMethod::__construct() expects exactly 1 parameter, 0 given in %s on line %d
-object(ReflectionMethod)#%d (2) {
- ["name"]=>
- string(0) ""
- ["class"]=>
- string(0) ""
-}
-
-Warning: ReflectionMethod::__construct() expects exactly 1 parameter, 3 given in %s on line %d
-object(ReflectionMethod)#%d (2) {
- ["name"]=>
- string(0) ""
- ["class"]=>
- string(0) ""
-}
+Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 0 given
+Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 3 given
Warning: ReflectionMethod::isFinal() expects exactly 0 parameters, 1 given in %s on line %d
NULL
diff --git a/ext/reflection/tests/ReflectionMethod_constructor_error2.phpt b/ext/reflection/tests/ReflectionMethod_constructor_error2.phpt
index 1c2d3a138f..85f8097825 100644
--- a/ext/reflection/tests/ReflectionMethod_constructor_error2.phpt
+++ b/ext/reflection/tests/ReflectionMethod_constructor_error2.phpt
@@ -16,22 +16,47 @@ class TestClass
try {
echo "Too few arguments:\n";
$methodInfo = new ReflectionMethod();
-} catch (Exception $e) {
- print $e->__toString();
+} catch (ReflectionException $re) {
+ echo "Ok - ".$re->getMessage().PHP_EOL;
}
try {
echo "\nToo many arguments:\n";
$methodInfo = new ReflectionMethod("TestClass", "foo", true);
-} catch (Exception $e) {
- print $e->__toString();
+} catch (ReflectionException $re) {
+ echo "Ok - ".$re->getMessage().PHP_EOL;
+}
+
+
+try {
+ //invalid class
+ $methodInfo = new ReflectionMethod("InvalidClassName", "foo");
+} catch (ReflectionException $re) {
+ echo "Ok - ".$re->getMessage().PHP_EOL;
+}
+
+
+try {
+ //invalid 1st param
+ $methodInfo = new ReflectionMethod([], "foo");
+} catch (ReflectionException $re) {
+ echo "Ok - ".$re->getMessage().PHP_EOL;
+}
+
+try{
+ //invalid 2nd param
+ $methodInfo = new ReflectionMethod("TestClass", []);
+} catch (ReflectionException $re) {
+ echo "Ok - ".$re->getMessage().PHP_EOL;
}
?>
--EXPECTF--
Too few arguments:
-
-Warning: ReflectionMethod::__construct() expects exactly 1 parameter, 0 given in %s on line 12
+Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 0 given
Too many arguments:
+Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 3 given
+Ok - Class InvalidClassName does not exist
+Ok - The parameter class is expected to be either a string or an object
+Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 2 given
-Warning: ReflectionMethod::__construct() expects exactly 1 parameter, 3 given in %s on line 18
diff --git a/ext/reflection/tests/ReflectionParameter_invalidMethodInConstructor.phpt b/ext/reflection/tests/ReflectionParameter_invalidMethodInConstructor.phpt
index 3118c17be8..1775dee514 100644
--- a/ext/reflection/tests/ReflectionParameter_invalidMethodInConstructor.phpt
+++ b/ext/reflection/tests/ReflectionParameter_invalidMethodInConstructor.phpt
@@ -6,7 +6,7 @@ ReflectionParameter::__construct(): Invalid method as constructor
// Invalid class name
try {
new ReflectionParameter (array ('A', 'b'), 0);
-} catch (ReflectionException $e) { echo $e->getMessage ()."\n"; }
+} catch (ReflectionException $e) { echo $e->getMessage()."\n"; }
// Invalid class method
try {
@@ -18,14 +18,31 @@ try {
new ReflectionParameter (array (new C, 'b'), 0);
} catch (ReflectionException $e) { echo $e->getMessage ()."\n"; }
-echo "Done.\n";
class C {
}
+try {
+ new ReflectionParameter(array ('A', 'b'));
+}
+catch(ReflectionException $e) {
+ printf( "Ok - %s\n", $e->getMessage());
+}
+
+try {
+ new ReflectionParameter(0, 0);
+}
+catch(ReflectionException $e) {
+ printf( "Ok - %s\n", $e->getMessage());
+}
+
+echo "Done.\n";
+
?>
--EXPECTF--
Class A does not exist
Method C::b() does not exist
Method C::b() does not exist
+Ok - ReflectionParameter::__construct() expects exactly 2 parameters, 1 given
+Ok - The parameter class is expected to be either a string, an array(class, method) or a callable object
Done.
diff --git a/ext/reflection/tests/ReflectionProperty_error.phpt b/ext/reflection/tests/ReflectionProperty_error.phpt
index 56de6e1f2e..d3910296b5 100644
--- a/ext/reflection/tests/ReflectionProperty_error.phpt
+++ b/ext/reflection/tests/ReflectionProperty_error.phpt
@@ -7,9 +7,27 @@ class C {
public static $p;
}
-var_dump(new ReflectionProperty());
-var_dump(new ReflectionProperty('C::p'));
-var_dump(new ReflectionProperty('C', 'p', 'x'));
+try {
+ new ReflectionProperty();
+}
+catch(ReflectionException $re) {
+ echo "Ok - ".$re->getMessage().PHP_EOL;
+}
+try {
+ new ReflectionProperty('C::p');
+}
+catch(ReflectionException $re) {
+ echo "Ok - ".$re->getMessage().PHP_EOL;
+}
+
+try {
+ new ReflectionProperty('C', 'p', 'x');
+}
+catch(ReflectionException $re) {
+ echo "Ok - ".$re->getMessage().PHP_EOL;
+}
+
+
$rp = new ReflectionProperty('C', 'p');
var_dump($rp->getName(1));
var_dump($rp->isPrivate(1));
@@ -21,29 +39,9 @@ var_dump($rp->isDefault(1));
?>
--EXPECTF--
-Warning: ReflectionProperty::__construct() expects exactly 2 parameters, 0 given in %s on line %d
-object(ReflectionProperty)#%d (2) {
- ["name"]=>
- string(0) ""
- ["class"]=>
- string(0) ""
-}
-
-Warning: ReflectionProperty::__construct() expects exactly 2 parameters, 1 given in %s on line %d
-object(ReflectionProperty)#%d (2) {
- ["name"]=>
- string(0) ""
- ["class"]=>
- string(0) ""
-}
-
-Warning: ReflectionProperty::__construct() expects exactly 2 parameters, 3 given in %s on line %d
-object(ReflectionProperty)#%d (2) {
- ["name"]=>
- string(0) ""
- ["class"]=>
- string(0) ""
-}
+Ok - ReflectionProperty::__construct() expects exactly 2 parameters, 0 given
+Ok - ReflectionProperty::__construct() expects exactly 2 parameters, 1 given
+Ok - ReflectionProperty::__construct() expects exactly 2 parameters, 3 given
Warning: ReflectionProperty::getName() expects exactly 0 parameters, 1 given in %s on line %d
NULL
diff --git a/ext/spl/spl_fixedarray.c b/ext/spl/spl_fixedarray.c
index cd83a17b56..9dbfa61344 100644
--- a/ext/spl/spl_fixedarray.c
+++ b/ext/spl/spl_fixedarray.c
@@ -561,7 +561,14 @@ SPL_METHOD(SplFixedArray, __construct)
spl_fixedarray_object *intern;
zend_long size = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &size) == FAILURE) {
+ 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) {
return;
}
diff --git a/ext/spl/tests/SplFixedArray__construct_param_array.phpt b/ext/spl/tests/SplFixedArray__construct_param_array.phpt
index 1d78695d4a..aa5933ebdb 100644
--- a/ext/spl/tests/SplFixedArray__construct_param_array.phpt
+++ b/ext/spl/tests/SplFixedArray__construct_param_array.phpt
@@ -5,8 +5,13 @@ PHPNW Test Fest 2009 - Jordan Hatch
--FILE--
<?php
-$array = new SplFixedArray( array("string", 1) );
+try {
+ $array = new SplFixedArray( array("string", 1) );
+}
+catch(InvalidArgumentException $iae) {
+ echo "Ok - ".$iae->getMessage().PHP_EOL;
+}
?>
--EXPECTF--
-Warning: SplFixedArray::__construct() expects parameter 1 to be integer, array given in %s on line %d \ No newline at end of file
+Ok - SplFixedArray::__construct() expects parameter 1 to be integer, array given \ No newline at end of file
diff --git a/ext/spl/tests/SplFixedArray__construct_param_string.phpt b/ext/spl/tests/SplFixedArray__construct_param_string.phpt
index 99742e3eb7..411d7402df 100644
--- a/ext/spl/tests/SplFixedArray__construct_param_string.phpt
+++ b/ext/spl/tests/SplFixedArray__construct_param_string.phpt
@@ -4,9 +4,14 @@ SplFixedArray::__construct() with string passed as parameter.
PHPNW Test Fest 2009 - Jordan Hatch
--FILE--
<?php
+try {
+ $array = new SplFixedArray( "string" );
+}
+catch(InvalidArgumentException $iae) {
+ echo "Ok - ".$iae->getMessage().PHP_EOL;
+}
-$array = new SplFixedArray( "string" );
?>
--EXPECTF--
-Warning: SplFixedArray::__construct() expects parameter 1 to be integer, %unicode_string_optional% given in %s on line %d
+Ok - SplFixedArray::__construct() expects parameter 1 to be integer, %unicode_string_optional% given
diff --git a/ext/spl/tests/SplFixedArray_construct_param_SplFixedArray.phpt b/ext/spl/tests/SplFixedArray_construct_param_SplFixedArray.phpt
index e91f110cd4..10d4c64a0c 100644
--- a/ext/spl/tests/SplFixedArray_construct_param_SplFixedArray.phpt
+++ b/ext/spl/tests/SplFixedArray_construct_param_SplFixedArray.phpt
@@ -4,10 +4,13 @@ Create an SplFixedArray using an SplFixedArray object.
Philip Norton philipnorton42@gmail.com
--FILE--
<?php
-$array = new SplFixedArray(new SplFixedArray(3));
-var_dump($array);
+try {
+ $array = new SplFixedArray(new SplFixedArray(3));
+}
+catch(InvalidArgumentException $iae) {
+ echo "Ok - ".$iae->getMessage().PHP_EOL;
+}
+
?>
--EXPECTF--
-Warning: SplFixedArray::__construct() expects parameter 1 to be integer, object given in %s on line %d
-object(SplFixedArray)#1 (0) {
-} \ No newline at end of file
+Ok - SplFixedArray::__construct() expects parameter 1 to be integer, object given
diff --git a/ext/spl/tests/fixedarray_005.phpt b/ext/spl/tests/fixedarray_005.phpt
index fdd78f06a2..72970a9a1f 100644
--- a/ext/spl/tests/fixedarray_005.phpt
+++ b/ext/spl/tests/fixedarray_005.phpt
@@ -5,8 +5,14 @@ SPL: FixedArray: Trying to instantiate passing object to constructor parameter
$b = new stdClass;
-$a = new SplFixedArray($b);
+try {
+ $a = new SplFixedArray($b);
+}
+catch(InvalidArgumentException $iae) {
+ echo "Ok - ".$iae->getMessage().PHP_EOL;
+}
+
?>
--EXPECTF--
-Warning: SplFixedArray::__construct() expects parameter 1 to be integer, object given in %s on line %d
+Ok - SplFixedArray::__construct() expects parameter 1 to be integer, object given
diff --git a/ext/spl/tests/fixedarray_009.phpt b/ext/spl/tests/fixedarray_009.phpt
index c386fc638e..d67c7ccb69 100644
--- a/ext/spl/tests/fixedarray_009.phpt
+++ b/ext/spl/tests/fixedarray_009.phpt
@@ -3,8 +3,12 @@ SPL: FixedArray: Trying to instantiate passing string to construtor parameter
--FILE--
<?php
-$a = new SplFixedArray('FOO');
-
+try {
+ $a = new SplFixedArray('FOO');
+}
+catch(InvalidArgumentException $iae) {
+ echo "Ok - ".$iae->getMessage().PHP_EOL;
+}
?>
--EXPECTF--
-Warning: SplFixedArray::__construct() expects parameter 1 to be integer, string given in %s on line %d
+Ok - SplFixedArray::__construct() expects parameter 1 to be integer, string given
diff --git a/ext/spl/tests/fixedarray_015.phpt b/ext/spl/tests/fixedarray_015.phpt
index 6e31a42532..f12d83bb39 100644
--- a/ext/spl/tests/fixedarray_015.phpt
+++ b/ext/spl/tests/fixedarray_015.phpt
@@ -3,47 +3,15 @@ SPL: FixedArray: accessing uninitialized array
--FILE--
<?php
-$a = new SplFixedArray('');
-
-try {
- var_dump($a[1]);
-} catch (Exception $e) {
- echo $e->getMessage(), "\n";
-}
-try {
- $a[1] = 1;
-} catch (Exception $e) {
- echo $e->getMessage(), "\n";
-}
try {
- var_dump(count($a[1]));
-} catch (Exception $e) {
- echo $e->getMessage(), "\n";
+ $a = new SplFixedArray('');
}
-try {
- var_dump($a->getSize());
-} catch (Exception $e) {
- echo $e->getMessage(), "\n";
-}
-try {
- foreach ($a as $v) {
- }
-} catch (Exception $e) {
- echo $e->getMessage(), "\n";
-}
-try {
- var_dump($a->setSize(10));
-} catch (Exception $e) {
- echo $e->getMessage(), "\n";
+catch(InvalidArgumentException $iae) {
+ echo "Ok - ".$iae->getMessage().PHP_EOL;
}
echo "Done\n";
?>
--EXPECTF--
-Warning: SplFixedArray::__construct() expects parameter 1 to be integer, string given in %s on line %d
-Index invalid or out of range
-Index invalid or out of range
-Index invalid or out of range
-int(0)
-bool(true)
+Ok - SplFixedArray::__construct() expects parameter 1 to be integer, string given
Done