summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS1
-rw-r--r--Zend/zend_API.c9
-rw-r--r--Zend/zend_API.h6
-rw-r--r--Zend/zend_vm_def.h7
-rw-r--r--Zend/zend_vm_execute.h38
-rw-r--r--ext/com_dotnet/com_com.c2
-rw-r--r--ext/com_dotnet/com_dotnet.c3
-rw-r--r--ext/date/php_date.c10
-rw-r--r--ext/fileinfo/fileinfo.c49
-rw-r--r--ext/fileinfo/tests/bug61173.phpt7
-rw-r--r--ext/fileinfo/tests/finfo_open_error.phpt8
-rw-r--r--ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp11
-rw-r--r--ext/intl/calendar/gregoriancalendar_methods.cpp13
-rw-r--r--ext/intl/collator/collator_create.c10
-rw-r--r--ext/intl/converter/converter.c11
-rw-r--r--ext/intl/dateformat/dateformat_create.cpp11
-rw-r--r--ext/intl/formatter/formatter_main.c10
-rw-r--r--ext/intl/intl_common.h2
-rw-r--r--ext/intl/intl_error.c2
-rw-r--r--ext/intl/msgformat/msgformat.c10
-rw-r--r--ext/intl/resourcebundle/resourcebundle_class.c11
-rw-r--r--ext/intl/spoofchecker/spoofchecker_create.c5
-rw-r--r--ext/intl/tests/breakiter___construct_error.phpt56
-rw-r--r--ext/intl/tests/bug62017.phpt14
-rw-r--r--ext/intl/tests/bug62081.phpt7
-rw-r--r--ext/intl/tests/dateformat___construct_bad_tz_cal.phpt35
-rw-r--r--ext/intl/tests/dateformat_calendars.phpt7
-rw-r--r--ext/intl/tests/dateformat_calendars_variant2.phpt7
-rw-r--r--ext/intl/tests/formatter_fail.phpt28
-rw-r--r--ext/intl/tests/gregoriancalendar___construct_error.phpt26
-rw-r--r--ext/intl/tests/msgfmt_fail.phpt43
-rw-r--r--ext/intl/tests/msgfmt_fail2.phpt43
-rw-r--r--ext/intl/tests/ut_common.inc20
-rw-r--r--ext/pdo/pdo_dbh.c26
-rw-r--r--ext/pdo/pdo_stmt.c6
-rw-r--r--ext/pdo/tests/pdo_036.phpt7
-rw-r--r--ext/pdo/tests/pdorow.phpt6
-rw-r--r--ext/pdo_mysql/tests/pdo_mysql___construct.phpt7
-rw-r--r--ext/pdo_mysql/tests/pdo_mysql___construct_options.phpt7
-rw-r--r--ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt3
-rw-r--r--ext/phar/phar_object.c21
-rw-r--r--ext/phar/tests/badparameters.phpt31
-rw-r--r--ext/phar/tests/bug60261.phpt8
-rw-r--r--ext/phar/tests/pharfileinfo_construct.phpt10
-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
58 files changed, 665 insertions, 379 deletions
diff --git a/NEWS b/NEWS
index d9bbac2391..5e44a7938c 100644
--- a/NEWS
+++ b/NEWS
@@ -59,6 +59,7 @@
. Implemented the RFC `Scalar Type Decalarations v0.5`. (Anthony)
. Implemented the RFC `Group Use Declarations`. (Marcio)
. Implemented the RFC `Continue Output Buffering`. (Mike)
+ . Implemented the RFC `Constructor behaviour of internal classes`. (Dan, Dmitry)
- Curl:
. Fixed bug #68937 (Segfault in curl_multi_exec). (Laruence)
diff --git a/Zend/zend_API.c b/Zend/zend_API.c
index e6f94798d0..4295159c7b 100644
--- a/Zend/zend_API.c
+++ b/Zend/zend_API.c
@@ -4128,15 +4128,6 @@ ZEND_API zend_string *zend_resolve_method_name(zend_class_entry *ce, zend_functi
}
/* }}} */
-ZEND_API void zend_ctor_make_null(zend_execute_data *execute_data) /* {{{ */
-{
- if (EX(return_value)) {
- Z_OBJ_P(EX(return_value)) = NULL;
- ZVAL_NULL(EX(return_value));
- }
-}
-/* }}} */
-
ZEND_API const char *zend_get_object_type(const zend_class_entry *ce) /* {{{ */
{
if(ce->ce_flags & ZEND_ACC_TRAIT) {
diff --git a/Zend/zend_API.h b/Zend/zend_API.h
index 694c818f60..b70dd26ef8 100644
--- a/Zend/zend_API.h
+++ b/Zend/zend_API.h
@@ -538,8 +538,6 @@ ZEND_API int zend_set_local_var_str(const char *name, size_t len, zval *value, i
ZEND_API zend_string *zend_find_alias_name(zend_class_entry *ce, zend_string *name);
ZEND_API zend_string *zend_resolve_method_name(zend_class_entry *ce, zend_function *f);
-ZEND_API void zend_ctor_make_null(zend_execute_data *execute_data);
-
ZEND_API const char *zend_get_object_type(const zend_class_entry *ce);
#define add_method(arg, key, method) add_assoc_function((arg), (key), (method))
@@ -651,10 +649,6 @@ END_EXTERN_C()
} \
} while (0)
-/* May be used in internal constructors to make them return NULL */
-#define ZEND_CTOR_MAKE_NULL() \
- zend_ctor_make_null(execute_data)
-
#define RETURN_ZVAL_FAST(z) { RETVAL_ZVAL_FAST(z); return; }
#define HASH_OF(p) (Z_TYPE_P(p)==IS_ARRAY ? Z_ARRVAL_P(p) : ((Z_TYPE_P(p)==IS_OBJECT ? Z_OBJ_HT_P(p)->get_properties((p)) : NULL)))
diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h
index 666037631f..dfa83df734 100644
--- a/Zend/zend_vm_def.h
+++ b/Zend/zend_vm_def.h
@@ -2962,10 +2962,6 @@ ZEND_VM_HANDLER(113, ZEND_INIT_STATIC_METHOD_CALL, CONST|VAR, CONST|TMPVAR|UNUSE
EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call));
- if (OP2_TYPE == IS_UNUSED) {
- EX(call)->return_value = NULL;
- }
-
CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
@@ -4720,9 +4716,6 @@ ZEND_VM_HANDLER(68, ZEND_NEW, CONST|VAR, ANY)
if (EXPECTED(RETURN_VALUE_USED(opline))) {
ZVAL_COPY(EX_VAR(opline->result.var), &object_zval);
- EX(call)->return_value = EX_VAR(opline->result.var);
- } else {
- EX(call)->return_value = NULL;
}
CHECK_EXCEPTION();
diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h
index a4c2f352e7..50bb1cc508 100644
--- a/Zend/zend_vm_execute.h
+++ b/Zend/zend_vm_execute.h
@@ -3112,9 +3112,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_NEW_SPEC_CONST_HANDLER(ZEND_OP
if (EXPECTED(RETURN_VALUE_USED(opline))) {
ZVAL_COPY(EX_VAR(opline->result.var), &object_zval);
- EX(call)->return_value = EX_VAR(opline->result.var);
- } else {
- EX(call)->return_value = NULL;
}
CHECK_EXCEPTION();
@@ -5104,10 +5101,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_C
EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call));
- if (IS_CONST == IS_UNUSED) {
- EX(call)->return_value = NULL;
- }
-
CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
@@ -7032,10 +7025,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_C
EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call));
- if (IS_UNUSED == IS_UNUSED) {
- EX(call)->return_value = NULL;
- }
-
CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
@@ -8520,10 +8509,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_C
EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call));
- if (IS_CV == IS_UNUSED) {
- EX(call)->return_value = NULL;
- }
-
CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
@@ -10071,10 +10056,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_C
EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call));
- if ((IS_TMP_VAR|IS_VAR) == IS_UNUSED) {
- EX(call)->return_value = NULL;
- }
-
CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
@@ -13851,9 +13832,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_NEW_SPEC_VAR_HANDLER(ZEND_OPCO
if (EXPECTED(RETURN_VALUE_USED(opline))) {
ZVAL_COPY(EX_VAR(opline->result.var), &object_zval);
- EX(call)->return_value = EX_VAR(opline->result.var);
- } else {
- EX(call)->return_value = NULL;
}
CHECK_EXCEPTION();
@@ -15938,10 +15916,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_V
EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call));
- if (IS_CONST == IS_UNUSED) {
- EX(call)->return_value = NULL;
- }
-
CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
@@ -17515,10 +17489,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_V
EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call));
- if (IS_UNUSED == IS_UNUSED) {
- EX(call)->return_value = NULL;
- }
-
CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
@@ -19134,10 +19104,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_V
EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call));
- if (IS_CV == IS_UNUSED) {
- EX(call)->return_value = NULL;
- }
-
CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
@@ -20695,10 +20661,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_V
EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call));
- if ((IS_TMP_VAR|IS_VAR) == IS_UNUSED) {
- EX(call)->return_value = NULL;
- }
-
CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
diff --git a/ext/com_dotnet/com_com.c b/ext/com_dotnet/com_com.c
index d61d933e7a..80ef70e7e0 100644
--- a/ext/com_dotnet/com_com.c
+++ b/ext/com_dotnet/com_com.c
@@ -66,7 +66,6 @@ PHP_FUNCTION(com_create_instance)
&typelib_name, &typelib_name_len)) {
php_com_throw_exception(E_INVALIDARG, "Could not create COM object - invalid arguments!");
- ZEND_CTOR_MAKE_NULL();
return;
}
@@ -230,7 +229,6 @@ PHP_FUNCTION(com_create_instance)
php_com_throw_exception(res, msg);
efree(msg);
- ZEND_CTOR_MAKE_NULL();
return;
}
diff --git a/ext/com_dotnet/com_dotnet.c b/ext/com_dotnet/com_dotnet.c
index 974876a853..7e0124b062 100644
--- a/ext/com_dotnet/com_dotnet.c
+++ b/ext/com_dotnet/com_dotnet.c
@@ -208,7 +208,6 @@ PHP_FUNCTION(com_dotnet_create_instance)
if (err)
LocalFree(err);
php_com_throw_exception(hr, buf);
- ZEND_CTOR_MAKE_NULL();
return;
}
stuff = (struct dotnet_runtime_stuff*)COMG(dotnet_runtime_stuff);
@@ -248,7 +247,6 @@ PHP_FUNCTION(com_dotnet_create_instance)
&datatype_name, &datatype_name_len,
&obj->code_page)) {
php_com_throw_exception(E_INVALIDARG, "Could not create .Net object - invalid arguments!");
- ZEND_CTOR_MAKE_NULL();
return;
}
@@ -314,7 +312,6 @@ PHP_FUNCTION(com_dotnet_create_instance)
LocalFree(err);
}
php_com_throw_exception(hr, buf);
- ZEND_CTOR_MAKE_NULL();
return;
}
}
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index b3f6a27c9d..7ca3aad266 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -2670,9 +2670,7 @@ PHP_METHOD(DateTime, __construct)
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)) {
- if (!php_date_initialize(Z_PHPDATE_P(getThis()), time_str, time_str_len, NULL, timezone_object, 1)) {
- ZEND_CTOR_MAKE_NULL();
- }
+ php_date_initialize(Z_PHPDATE_P(getThis()), time_str, time_str_len, NULL, timezone_object, 1);
}
zend_restore_error_handling(&error_handling);
}
@@ -3679,9 +3677,7 @@ PHP_METHOD(DateTimeZone, __construct)
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());
- if (FAILURE == timezone_initialize(tzobj, tz)) {
- ZEND_CTOR_MAKE_NULL();
- }
+ timezone_initialize(tzobj, tz);
}
zend_restore_error_handling(&error_handling);
}
@@ -4113,8 +4109,6 @@ PHP_METHOD(DateInterval, __construct)
diobj = Z_PHPINTERVAL_P(getThis());
diobj->diff = reltime;
diobj->initialized = 1;
- } else {
- ZEND_CTOR_MAKE_NULL();
}
}
zend_restore_error_handling(&error_handling);
diff --git a/ext/fileinfo/fileinfo.c b/ext/fileinfo/fileinfo.c
index b4a556d57b..075397105b 100644
--- a/ext/fileinfo/fileinfo.c
+++ b/ext/fileinfo/fileinfo.c
@@ -282,15 +282,6 @@ PHP_MINFO_FUNCTION(fileinfo)
}
/* }}} */
-#define FILEINFO_DESTROY_OBJECT(object) \
- do { \
- if (object) { \
- zend_object_store_ctor_failed(Z_OBJ_P(object)); \
- Z_OBJ_P(object) = NULL; \
- ZEND_CTOR_MAKE_NULL(); \
- } \
- } while (0)
-
/* {{{ proto resource finfo_open([int options [, string arg]])
Create a new fileinfo resource. */
PHP_FUNCTION(finfo_open)
@@ -301,9 +292,18 @@ PHP_FUNCTION(finfo_open)
php_fileinfo *finfo;
FILEINFO_DECLARE_INIT_OBJECT(object)
char resolved_path[MAXPATHLEN];
+ zend_error_handling zeh;
+ if (object) {
+ zend_replace_error_handling(EH_THROW, NULL, &zeh);
+ }
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|lp", &options, &file, &file_len) == FAILURE) {
- FILEINFO_DESTROY_OBJECT(object);
+ if (object) {
+ zend_restore_error_handling(&zeh);
+ if (!EG(exception)) {
+ zend_throw_exception(NULL, "Constructor failed", 0);
+ }
+ }
RETURN_FALSE;
}
@@ -322,11 +322,21 @@ PHP_FUNCTION(finfo_open)
} else if (file && *file) { /* user specified file, perform open_basedir checks */
if (php_check_open_basedir(file)) {
- FILEINFO_DESTROY_OBJECT(object);
+ if (object) {
+ zend_restore_error_handling(&zeh);
+ if (!EG(exception)) {
+ zend_throw_exception(NULL, "Constructor failed", 0);
+ }
+ }
RETURN_FALSE;
}
if (!expand_filepath_with_mode(file, resolved_path, NULL, 0, CWD_EXPAND)) {
- FILEINFO_DESTROY_OBJECT(object);
+ if (object) {
+ zend_restore_error_handling(&zeh);
+ if (!EG(exception)) {
+ zend_throw_exception(NULL, "Constructor failed", 0);
+ }
+ }
RETURN_FALSE;
}
file = resolved_path;
@@ -340,7 +350,12 @@ PHP_FUNCTION(finfo_open)
if (finfo->magic == NULL) {
efree(finfo);
php_error_docref(NULL, E_WARNING, "Invalid mode '%pd'.", options);
- FILEINFO_DESTROY_OBJECT(object);
+ if (object) {
+ zend_restore_error_handling(&zeh);
+ if (!EG(exception)) {
+ zend_throw_exception(NULL, "Constructor failed", 0);
+ }
+ }
RETURN_FALSE;
}
@@ -348,11 +363,17 @@ PHP_FUNCTION(finfo_open)
php_error_docref(NULL, E_WARNING, "Failed to load magic database at '%s'.", file);
magic_close(finfo->magic);
efree(finfo);
- FILEINFO_DESTROY_OBJECT(object);
+ if (object) {
+ zend_restore_error_handling(&zeh);
+ if (!EG(exception)) {
+ zend_throw_exception(NULL, "Constructor failed", 0);
+ }
+ }
RETURN_FALSE;
}
if (object) {
+ zend_restore_error_handling(&zeh);
FILEINFO_REGISTER_OBJECT(object, finfo);
} else {
RETURN_RES(zend_register_resource(finfo, le_fileinfo));
diff --git a/ext/fileinfo/tests/bug61173.phpt b/ext/fileinfo/tests/bug61173.phpt
index 521176fe76..838faf5b7d 100644
--- a/ext/fileinfo/tests/bug61173.phpt
+++ b/ext/fileinfo/tests/bug61173.phpt
@@ -10,5 +10,8 @@ if (!class_exists('finfo'))
$finfo = new finfo(1, '', false);
var_dump($finfo);
--EXPECTF--
-Warning: finfo::finfo() expects at most 2 parameters, 3 given in %s on line %d
-NULL
+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
diff --git a/ext/fileinfo/tests/finfo_open_error.phpt b/ext/fileinfo/tests/finfo_open_error.phpt
index ed43a8b453..d02be60e31 100644
--- a/ext/fileinfo/tests/finfo_open_error.phpt
+++ b/ext/fileinfo/tests/finfo_open_error.phpt
@@ -46,6 +46,8 @@ 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)
-Warning: finfo::finfo() expects parameter 1 to be integer, string given in %sfinfo_open_error.php on line 18
-NULL
-===DONE===
+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
diff --git a/ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp b/ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp
index c112134124..b43f8212d0 100644
--- a/ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp
+++ b/ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp
@@ -24,6 +24,7 @@ extern "C" {
}
#include "../intl_convertcpp.h"
+#include "../intl_common.h"
static inline RuleBasedBreakIterator *fetch_rbbi(BreakIterator_object *bio) {
return (RuleBasedBreakIterator*)bio->biter;
@@ -97,15 +98,17 @@ static void _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
U_CFUNC PHP_METHOD(IntlRuleBasedBreakIterator, __construct)
{
- zval orig_this = *getThis();
+ zend_error_handling error_handling;
+ zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
return_value = getThis();
_php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU);
-
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
- zend_object_store_ctor_failed(Z_OBJ(orig_this));
- ZEND_CTOR_MAKE_NULL();
+ if (!EG(exception)) {
+ zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
+ }
}
+ zend_restore_error_handling(&error_handling);
}
U_CFUNC PHP_FUNCTION(rbbi_get_rules)
diff --git a/ext/intl/calendar/gregoriancalendar_methods.cpp b/ext/intl/calendar/gregoriancalendar_methods.cpp
index 2ae5737227..d9572a0668 100644
--- a/ext/intl/calendar/gregoriancalendar_methods.cpp
+++ b/ext/intl/calendar/gregoriancalendar_methods.cpp
@@ -25,11 +25,13 @@
#include <unicode/gregocal.h>
extern "C" {
#include "../php_intl.h"
+#include "../intl_common.h"
#define USE_TIMEZONE_POINTER 1
#include "../timezone/timezone_class.h"
#define USE_CALENDAR_POINTER 1
#include "calendar_class.h"
#include <ext/date/php_date.h>
+#include "zend_exceptions.h"
}
static inline GregorianCalendar *fetch_greg(Calendar_object *co) {
@@ -189,17 +191,18 @@ U_CFUNC PHP_FUNCTION(intlgregcal_create_instance)
U_CFUNC PHP_METHOD(IntlGregorianCalendar, __construct)
{
- zval orig_this = *getThis();
- intl_error_reset(NULL);
+ zend_error_handling error_handling;
+ 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);
-
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
- zend_object_store_ctor_failed(Z_OBJ(orig_this));
- ZEND_CTOR_MAKE_NULL();
+ if (!EG(exception)) {
+ zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
+ }
}
+ zend_restore_error_handling(&error_handling);
}
U_CFUNC PHP_FUNCTION(intlgregcal_set_gregorian_change)
diff --git a/ext/intl/collator/collator_create.c b/ext/intl/collator/collator_create.c
index b2058422c2..c6bc3fd209 100644
--- a/ext/intl/collator/collator_create.c
+++ b/ext/intl/collator/collator_create.c
@@ -72,15 +72,17 @@ PHP_FUNCTION( collator_create )
*/
PHP_METHOD( Collator, __construct )
{
- zval orig_this = *getThis();
+ zend_error_handling error_handling;
+ zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
return_value = getThis();
collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
-
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
- zend_object_store_ctor_failed(Z_OBJ(orig_this));
- ZEND_CTOR_MAKE_NULL();
+ if (!EG(exception)) {
+ zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
+ }
}
+ zend_restore_error_handling(&error_handling);
}
/* }}} */
diff --git a/ext/intl/converter/converter.c b/ext/intl/converter/converter.c
index 9bba427409..fd3aced34d 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);
+ 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);
return;
diff --git a/ext/intl/dateformat/dateformat_create.cpp b/ext/intl/dateformat/dateformat_create.cpp
index f8cf77641f..b7ad7b5126 100644
--- a/ext/intl/dateformat/dateformat_create.cpp
+++ b/ext/intl/dateformat/dateformat_create.cpp
@@ -34,6 +34,7 @@ extern "C" {
}
#include "dateformat_helpers.h"
+#include "zend_exceptions.h"
/* {{{ */
static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
@@ -187,16 +188,18 @@ U_CFUNC PHP_FUNCTION( datefmt_create )
*/
U_CFUNC PHP_METHOD( IntlDateFormatter, __construct )
{
- zval orig_this = *getThis();
+ zend_error_handling error_handling;
+ zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
/* return_value param is being changed, therefore we will always return
* NULL here */
return_value = getThis();
datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
-
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
- zend_object_store_ctor_failed(Z_OBJ(orig_this));
- ZEND_CTOR_MAKE_NULL();
+ if (!EG(exception)) {
+ zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
+ }
}
+ zend_restore_error_handling(&error_handling);
}
/* }}} */
diff --git a/ext/intl/formatter/formatter_main.c b/ext/intl/formatter/formatter_main.c
index 60db673ff2..5d5a139688 100644
--- a/ext/intl/formatter/formatter_main.c
+++ b/ext/intl/formatter/formatter_main.c
@@ -90,15 +90,17 @@ PHP_FUNCTION( numfmt_create )
*/
PHP_METHOD( NumberFormatter, __construct )
{
- zval orig_this = *getThis();
+ zend_error_handling error_handling;
+ zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
return_value = getThis();
numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
-
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
- zend_object_store_ctor_failed(Z_OBJ(orig_this));
- ZEND_CTOR_MAKE_NULL();
+ if (!EG(exception)) {
+ zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
+ }
}
+ zend_restore_error_handling(&error_handling);
}
/* }}} */
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_error.c b/ext/intl/intl_error.c
index 28a2a244e2..a946705a76 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.
diff --git a/ext/intl/msgformat/msgformat.c b/ext/intl/msgformat/msgformat.c
index 707b38bd95..15d6ef8321 100644
--- a/ext/intl/msgformat/msgformat.c
+++ b/ext/intl/msgformat/msgformat.c
@@ -108,15 +108,17 @@ PHP_FUNCTION( msgfmt_create )
*/
PHP_METHOD( MessageFormatter, __construct )
{
- zval orig_this = *getThis();
+ zend_error_handling error_handling;
+ zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
return_value = getThis();
msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
-
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
- zend_object_store_ctor_failed(Z_OBJ(orig_this));
- ZEND_CTOR_MAKE_NULL();
+ if (!EG(exception)) {
+ zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
+ }
}
+ zend_restore_error_handling(&error_handling);
}
/* }}} */
diff --git a/ext/intl/resourcebundle/resourcebundle_class.c b/ext/intl/resourcebundle/resourcebundle_class.c
index b8d27c940a..d8d1aa0d9c 100644
--- a/ext/intl/resourcebundle/resourcebundle_class.c
+++ b/ext/intl/resourcebundle/resourcebundle_class.c
@@ -25,6 +25,7 @@
#include "php_intl.h"
#include "intl_data.h"
+#include "intl_common.h"
#include "resourcebundle/resourcebundle.h"
#include "resourcebundle/resourcebundle_iterator.h"
@@ -139,15 +140,17 @@ ZEND_END_ARG_INFO()
*/
PHP_METHOD( ResourceBundle, __construct )
{
- zval orig_this = *getThis();
+ zend_error_handling error_handling;
+ zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
return_value = getThis();
resourcebundle_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
-
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
- zend_object_store_ctor_failed(Z_OBJ(orig_this));
- ZEND_CTOR_MAKE_NULL();
+ if (!EG(exception)) {
+ zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
+ }
}
+ zend_restore_error_handling(&error_handling);
}
/* }}} */
diff --git a/ext/intl/spoofchecker/spoofchecker_create.c b/ext/intl/spoofchecker/spoofchecker_create.c
index d797015cf8..abe1d8e9cc 100644
--- a/ext/intl/spoofchecker/spoofchecker_create.c
+++ b/ext/intl/spoofchecker/spoofchecker_create.c
@@ -30,8 +30,12 @@ PHP_METHOD(Spoofchecker, __construct)
{
int checks;
SPOOFCHECKER_METHOD_INIT_VARS;
+ zend_error_handling error_handling;
+
+ zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
if (zend_parse_parameters_none() == FAILURE) {
+ zend_restore_error_handling(&error_handling);
return;
}
@@ -46,6 +50,7 @@ PHP_METHOD(Spoofchecker, __construct)
*/
checks = uspoof_getChecks(co->uspoof, SPOOFCHECKER_ERROR_CODE_P(co));
uspoof_setChecks(co->uspoof, checks & ~USPOOF_SINGLE_SCRIPT, SPOOFCHECKER_ERROR_CODE_P(co));
+ zend_restore_error_handling(&error_handling);
}
/* }}} */
diff --git a/ext/intl/tests/breakiter___construct_error.phpt b/ext/intl/tests/breakiter___construct_error.phpt
index 770f1403c7..bea65667fa 100644
--- a/ext/intl/tests/breakiter___construct_error.phpt
+++ b/ext/intl/tests/breakiter___construct_error.phpt
@@ -7,32 +7,44 @@ IntlRuleBasedBreakIterator::__construct(): arg errors
<?php
ini_set("intl.error_level", E_WARNING);
-//missing ; at the end:
-var_dump(new IntlRuleBasedBreakIterator('[\p{Letter}\uFFFD]+;[:number:]+'));
-var_dump(new IntlRuleBasedBreakIterator());
-var_dump(new IntlRuleBasedBreakIterator(1,2,3));
-var_dump(new IntlRuleBasedBreakIterator('[\p{Letter}\uFFFD]+;[:number:]+;', array()));
-var_dump(new IntlRuleBasedBreakIterator('[\p{Letter}\uFFFD]+;[:number:]+;', true));
+function print_exception($e) {
+ echo "\nException: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n";
+}
+//missing ; at the end:
+try {
+ var_dump(new IntlRuleBasedBreakIterator('[\p{Letter}\uFFFD]+;[:number:]+'));
+} catch (IntlException $e) {
+ print_exception($e);
+}
+try {
+ var_dump(new IntlRuleBasedBreakIterator());
+} catch (IntlException $e) {
+ print_exception($e);
+}
+try {
+ var_dump(new IntlRuleBasedBreakIterator(1,2,3));
+} catch (IntlException $e) {
+ print_exception($e);
+}
+try {
+ var_dump(new IntlRuleBasedBreakIterator('[\p{Letter}\uFFFD]+;[:number:]+;', array()));
+} catch (IntlException $e) {
+ print_exception($e);
+}
+try {
+ var_dump(new IntlRuleBasedBreakIterator('[\p{Letter}\uFFFD]+;[:number:]+;', true));
+} catch (IntlException $e) {
+ print_exception($e);
+}
--EXPECTF--
-Warning: IntlRuleBasedBreakIterator::__construct(): rbbi_create_instance: unable to create RuleBasedBreakIterator from rules (parse error on line 1, offset 31) in %s on line %d
-NULL
-
-Warning: IntlRuleBasedBreakIterator::__construct() expects at least 1 parameter, 0 given in %s on line %d
-
-Warning: IntlRuleBasedBreakIterator::__construct(): rbbi_create_instance: bad arguments in %s on line %d
-NULL
-
-Warning: IntlRuleBasedBreakIterator::__construct() expects at most 2 parameters, 3 given in %s on line %d
+Exception: IntlRuleBasedBreakIterator::__construct(): rbbi_create_instance: unable to create RuleBasedBreakIterator from rules (parse error on line 1, offset 31) in %s on line %d
-Warning: IntlRuleBasedBreakIterator::__construct(): rbbi_create_instance: bad arguments in %s on line %d
-NULL
+Exception: IntlRuleBasedBreakIterator::__construct() expects at least 1 parameter, 0 given in %s on line %d
-Warning: IntlRuleBasedBreakIterator::__construct() expects parameter 2 to be boolean, array given in %s on line %d
+Exception: IntlRuleBasedBreakIterator::__construct() expects at most 2 parameters, 3 given in %s on line %d
-Warning: IntlRuleBasedBreakIterator::__construct(): rbbi_create_instance: bad arguments in %s on line %d
-NULL
+Exception: IntlRuleBasedBreakIterator::__construct() expects parameter 2 to be boolean, array given in %s on line %d
-Warning: IntlRuleBasedBreakIterator::__construct(): rbbi_create_instance: unable to create instance from compiled rules in %s on line %d
-NULL
+Exception: IntlRuleBasedBreakIterator::__construct(): rbbi_create_instance: unable to create instance from compiled rules in %s on line %d
diff --git a/ext/intl/tests/bug62017.phpt b/ext/intl/tests/bug62017.phpt
index 50aeae4806..2f3c816f99 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(
- new IntlDateFormatter('', IntlDateFormatter::NONE, IntlDateFormatter::NONE, "Europe/Lisbon",
- IntlDateFormatter::GREGORIAN, "\x80"));
+try {
+ var_dump(
+ new IntlDateFormatter('', IntlDateFormatter::NONE, IntlDateFormatter::NONE, "Europe/Lisbon",
+ IntlDateFormatter::GREGORIAN, "\x80"));
+} catch (IntlException $e) {
+ echo PHP_EOL."Exception: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . 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
-
+Exception: IntlDateFormatter::__construct(): datefmt_create: error converting pattern to UTF-16 in %sbug62017.php on line %d
diff --git a/ext/intl/tests/bug62081.phpt b/ext/intl/tests/bug62081.phpt
index 44ad4beec7..263023ffac 100644
--- a/ext/intl/tests/bug62081.phpt
+++ b/ext/intl/tests/bug62081.phpt
@@ -12,5 +12,8 @@ ini_set('intl.error_level', E_WARNING);
$x = new IntlDateFormatter('en', 1, 1);
var_dump($x->__construct('en', 1, 1));
--EXPECTF--
-Warning: IntlDateFormatter::__construct(): datefmt_create: cannot call constructor twice in %s on line %d
-NULL
+Fatal error: Uncaught exception 'IntlException' with message 'IntlDateFormatter::__construct(): datefmt_create: cannot call constructor twice' in %sbug62081.php:4
+Stack trace:
+#0 %sbug62081.php(4): IntlDateFormatter->__construct('en', 1, 1)
+#1 {main}
+ thrown in %sbug62081.php on line 4
diff --git a/ext/intl/tests/dateformat___construct_bad_tz_cal.phpt b/ext/intl/tests/dateformat___construct_bad_tz_cal.phpt
index cfd9338717..d10ad42623 100644
--- a/ext/intl/tests/dateformat___construct_bad_tz_cal.phpt
+++ b/ext/intl/tests/dateformat___construct_bad_tz_cal.phpt
@@ -10,23 +10,32 @@ ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "pt_PT");
ini_set("date.timezone", 'Atlantic/Azores');
-var_dump(new IntlDateFormatter(NULL, 0, 0, 'bad timezone'));
-
-var_dump(new IntlDateFormatter(NULL, 0, 0, NULL, 3));
-
-var_dump(new IntlDateFormatter(NULL, 0, 0, NULL, new stdclass));
-
-
+function print_exception($e) {
+ echo "\nException: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n";
+}
+
+try {
+ var_dump(new IntlDateFormatter(NULL, 0, 0, 'bad timezone'));
+} catch (IntlException $e) {
+ print_exception($e);
+}
+try {
+ var_dump(new IntlDateFormatter(NULL, 0, 0, NULL, 3));
+} catch (IntlException $e) {
+ print_exception($e);
+}
+try {
+ var_dump(new IntlDateFormatter(NULL, 0, 0, NULL, new stdclass));
+} catch (IntlException $e) {
+ print_exception($e);
+}
?>
==DONE==
--EXPECTF--
-Warning: IntlDateFormatter::__construct(): datefmt_create: no such time zone: 'bad timezone' in %s on line %d
-NULL
+Exception: IntlDateFormatter::__construct(): datefmt_create: no such time zone: 'bad timezone' in %s on line %d
-Warning: IntlDateFormatter::__construct(): datefmt_create: invalid value for calendar type; it must be one of IntlDateFormatter::TRADITIONAL (locale's default calendar) or IntlDateFormatter::GREGORIAN. Alternatively, it can be an IntlCalendar object in %s on line %d
-NULL
+Exception: IntlDateFormatter::__construct(): datefmt_create: invalid value for calendar type; it must be one of IntlDateFormatter::TRADITIONAL (locale's default calendar) or IntlDateFormatter::GREGORIAN. Alternatively, it can be an IntlCalendar object in %s on line %d
-Warning: IntlDateFormatter::__construct(): datefmt_create: Invalid calendar argument; should be an integer or an IntlCalendar instance in %s on line %d
-NULL
+Exception: IntlDateFormatter::__construct(): datefmt_create: Invalid calendar argument; should be an integer or an IntlCalendar instance in %s on line %d
==DONE==
diff --git a/ext/intl/tests/dateformat_calendars.phpt b/ext/intl/tests/dateformat_calendars.phpt
index 7de6356455..13dde0f370 100644
--- a/ext/intl/tests/dateformat_calendars.phpt
+++ b/ext/intl/tests/dateformat_calendars.phpt
@@ -41,5 +41,8 @@ string(44) "Sunday, January 1, 2012 5:12:00 AM GMT+05:12"
string(44) "Sunday, January 1, 2012 5:12:00 AM GMT+05:12"
string(42) "Sunday, Tevet 6, 5772 5:12:00 AM GMT+05:12"
-Warning: IntlDateFormatter::__construct(): datefmt_create: invalid value for calendar type; it must be one of IntlDateFormatter::TRADITIONAL (locale's default calendar) or IntlDateFormatter::GREGORIAN. Alternatively, it can be an IntlCalendar object in %s on line %d
-==DONE==
+Fatal error: Uncaught exception 'IntlException' with message 'IntlDateFormatter::__construct(): datefmt_create: invalid value for calendar type; it must be one of IntlDateFormatter::TRADITIONAL (locale's default calendar) or IntlDateFormatter::GREGORIAN. Alternatively, it can be an IntlCalendar object' in %sdateformat_calendars.php:%d
+Stack trace:
+#0 %sdateformat_calendars.php(%d): IntlDateFormatter->__construct('en_US@calendar=...', 0, 0, 'GMT+05:12', -1)
+#1 {main}
+ thrown in %sdateformat_calendars.php on line %d
diff --git a/ext/intl/tests/dateformat_calendars_variant2.phpt b/ext/intl/tests/dateformat_calendars_variant2.phpt
index b3b1701c55..11a5026da0 100644
--- a/ext/intl/tests/dateformat_calendars_variant2.phpt
+++ b/ext/intl/tests/dateformat_calendars_variant2.phpt
@@ -42,5 +42,8 @@ string(47) "Sunday, January 1, 2012 at 5:12:00 AM GMT+05:12"
string(47) "Sunday, January 1, 2012 at 5:12:00 AM GMT+05:12"
string(48) "Sunday, Tevet 6, 5772 AM at 5:12:00 AM GMT+05:12"
-Warning: IntlDateFormatter::__construct(): datefmt_create: invalid value for calendar type; it must be one of IntlDateFormatter::TRADITIONAL (locale's default calendar) or IntlDateFormatter::GREGORIAN. Alternatively, it can be an IntlCalendar object in %sdateformat_calendars_variant2.php on line %d
-==DONE==
+Fatal error: Uncaught exception 'IntlException' with message 'IntlDateFormatter::__construct(): datefmt_create: invalid value for calendar type; it must be one of IntlDateFormatter::TRADITIONAL (locale's default calendar) or IntlDateFormatter::GREGORIAN. Alternatively, it can be an IntlCalendar object' in %sdateformat_calendars_variant2.php:27
+Stack trace:
+#0 %sdateformat_calendars_variant2.php(27): IntlDateFormatter->__construct('en_US@calendar=...', 0, 0, 'GMT+05:12', -1)
+#1 {main}
+ thrown in %sdateformat_calendars_variant2.php on line 27
diff --git a/ext/intl/tests/formatter_fail.phpt b/ext/intl/tests/formatter_fail.phpt
index 295f011008..f61cb14878 100644
--- a/ext/intl/tests/formatter_fail.phpt
+++ b/ext/intl/tests/formatter_fail.phpt
@@ -11,10 +11,19 @@ function err($fmt) {
}
}
+function print_exception($e) {
+ echo "\nException: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n";
+}
+
function crt($t, $l, $s) {
switch(true) {
case $t == "O":
- return new NumberFormatter($l, $s);
+ try {
+ return new NumberFormatter($l, $s);
+ } catch (IntlException $e) {
+ print_exception($e);
+ return null;
+ }
break;
case $t == "C":
return NumberFormatter::create($l, $s);
@@ -33,7 +42,12 @@ $args = array(
array("en_US", NumberFormatter::PATTERN_RULEBASED),
);
-$fmt = new NumberFormatter();
+try {
+ $fmt = new NumberFormatter();
+} catch (IntlException $e) {
+ print_exception($e);
+ $fmt = null;
+}
err($fmt);
$fmt = numfmt_create();
err($fmt);
@@ -51,7 +65,7 @@ foreach($args as $arg) {
?>
--EXPECTF--
-Warning: NumberFormatter::__construct() expects at least 2 parameters, 0 given in %s on line %d
+Exception: 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
@@ -59,11 +73,13 @@ 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
'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'
-Warning: NumberFormatter::__construct() expects parameter 1 to be string, array given in %s on line %d
+Exception: 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
@@ -71,9 +87,13 @@ 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
'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
'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'
diff --git a/ext/intl/tests/gregoriancalendar___construct_error.phpt b/ext/intl/tests/gregoriancalendar___construct_error.phpt
index 45229cf000..d81809793e 100644
--- a/ext/intl/tests/gregoriancalendar___construct_error.phpt
+++ b/ext/intl/tests/gregoriancalendar___construct_error.phpt
@@ -8,13 +8,23 @@ if (!extension_loaded('intl'))
<?php
ini_set("intl.error_level", E_WARNING);
+function print_exception($e) {
+ echo "\nException: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n";
+}
+
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 {
+ var_dump(new IntlGregorianCalendar(1,2,NULL,4));
+} catch (IntlException $e) {
+ print_exception($e);
+}
+try {
+ var_dump(new IntlGregorianCalendar(1,2,3,4,NULL,array()));
+} catch (IntlException $e) {
+ print_exception($e);
+}
--EXPECTF--
Warning: intlgregcal_create_instance(): intlgregcal_create_instance: too many arguments in %s on line %d
@@ -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
-
-Warning: IntlGregorianCalendar::__construct() expects parameter 6 to be integer, array given in %s on line %d
+Exception: IntlGregorianCalendar::__construct(): intlgregcal_create_instance: no variant with 4 arguments (excluding trailing NULLs) in %s on line %d
-Warning: IntlGregorianCalendar::__construct(): intlgregcal_create_instance: bad arguments in %s on line %d
-NULL
+Exception: IntlGregorianCalendar::__construct() expects parameter 6 to be integer, array given in %s on line %d
diff --git a/ext/intl/tests/msgfmt_fail.phpt b/ext/intl/tests/msgfmt_fail.phpt
index bffb71c56d..7c76598c0d 100644
--- a/ext/intl/tests/msgfmt_fail.phpt
+++ b/ext/intl/tests/msgfmt_fail.phpt
@@ -12,10 +12,19 @@ function err($fmt) {
}
}
+function print_exception($e) {
+ echo "\nException: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n";
+}
+
function crt($t, $l, $s) {
switch(true) {
case $t == "O":
- return new MessageFormatter($l, $s);
+ try {
+ return new MessageFormatter($l, $s);
+ } catch (IntlException $e) {
+ print_exception($e);
+ return null;
+ }
break;
case $t == "C":
return MessageFormatter::create($l, $s);
@@ -35,13 +44,23 @@ $args = array(
array("en_US", "\xD0"),
);
-$fmt = new MessageFormatter();
+try {
+ $fmt = new MessageFormatter();
+} catch (IntlException $e) {
+ print_exception($e);
+ $fmt = null;
+}
err($fmt);
$fmt = msgfmt_create();
err($fmt);
$fmt = MessageFormatter::create();
-err($fmt);
-$fmt = new MessageFormatter('en');
+err($fmt);
+try {
+ $fmt = new MessageFormatter('en');
+} catch (IntlException $e) {
+ print_exception($e);
+ $fmt = null;
+}
err($fmt);
$fmt = msgfmt_create('en');
err($fmt);
@@ -59,7 +78,7 @@ foreach($args as $arg) {
?>
--EXPECTF--
-Warning: MessageFormatter::__construct() expects exactly 2 parameters, 0 given in %s on line %d
+Exception: 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
@@ -68,7 +87,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
+Exception: 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
@@ -76,14 +95,18 @@ 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
'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
'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'
-Warning: MessageFormatter::__construct() expects parameter 1 to be string, array given in %s on line %d
+Exception: 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
@@ -91,12 +114,18 @@ 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
'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
'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
'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'
diff --git a/ext/intl/tests/msgfmt_fail2.phpt b/ext/intl/tests/msgfmt_fail2.phpt
index eee2424a50..0ab99cf633 100644
--- a/ext/intl/tests/msgfmt_fail2.phpt
+++ b/ext/intl/tests/msgfmt_fail2.phpt
@@ -12,10 +12,19 @@ function err($fmt) {
}
}
+function print_exception($e) {
+ echo "\nException: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n";
+}
+
function crt($t, $l, $s) {
switch(true) {
case $t == "O":
- return new MessageFormatter($l, $s);
+ try {
+ return new MessageFormatter($l, $s);
+ } catch (IntlException $e) {
+ print_exception($e);
+ return null;
+ }
break;
case $t == "C":
return MessageFormatter::create($l, $s);
@@ -35,13 +44,23 @@ $args = array(
array("en_US", "\xD0"),
);
-$fmt = new MessageFormatter();
+try {
+ $fmt = new MessageFormatter();
+} catch (IntlException $e) {
+ print_exception($e);
+ $fmt = null;
+}
err($fmt);
$fmt = msgfmt_create();
err($fmt);
$fmt = MessageFormatter::create();
-err($fmt);
-$fmt = new MessageFormatter('en');
+err($fmt);
+try {
+ $fmt = new MessageFormatter('en');
+} catch (IntlException $e) {
+ print_exception($e);
+ $fmt = null;
+}
err($fmt);
$fmt = msgfmt_create('en');
err($fmt);
@@ -59,7 +78,7 @@ foreach($args as $arg) {
?>
--EXPECTF--
-Warning: MessageFormatter::__construct() expects exactly 2 parameters, 0 given in %s on line %d
+Exception: 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
@@ -68,7 +87,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
+Exception: 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
@@ -76,14 +95,18 @@ 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
'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
'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'
-Warning: MessageFormatter::__construct() expects parameter 1 to be string, array given in %s on line %d
+Exception: 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
@@ -91,12 +114,18 @@ 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
'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
'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
'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'
diff --git a/ext/intl/tests/ut_common.inc b/ext/intl/tests/ut_common.inc
index 09be22bf5a..9f72bacae4 100644
--- a/ext/intl/tests/ut_common.inc
+++ b/ext/intl/tests/ut_common.inc
@@ -132,7 +132,15 @@ function ut_coll_set_default( $coll )
function ut_nfmt_create( $locale, $style, $pattern = null )
{
- return $GLOBALS['oo-mode'] ? new NumberFormatter( $locale, $style, $pattern ) : numfmt_create( $locale, $style, $pattern );
+ if ($GLOBALS['oo-mode']) {
+ try {
+ return new NumberFormatter( $locale, $style, $pattern );
+ } catch (Exception $e) {
+ return NULL;
+ }
+ } else {
+ return numfmt_create( $locale, $style, $pattern );
+ }
}
function ut_nfmt_format( $fmt, $number, $type = null )
{
@@ -392,7 +400,15 @@ function ut_datefmt_localtime( $fmt , $value , &$parse_pos=0 )
function ut_resourcebundle_create( $locale, $bundle, $fallback=true )
{
- return $GLOBALS['oo-mode'] ? new ResourceBundle($locale, $bundle, $fallback): resourcebundle_create($locale, $bundle, $fallback);
+ if ($GLOBALS['oo-mode']) {
+ try {
+ return new ResourceBundle($locale, $bundle, $fallback);
+ } catch (Exception $e) {
+ return NULL;
+ }
+ } else {
+ return resourcebundle_create($locale, $bundle, $fallback);
+ }
}
function ut_resourcebundle_count($bundle )
{
diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c
index de9a6abbdc..ed541543f9 100644
--- a/ext/pdo/pdo_dbh.c
+++ b/ext/pdo/pdo_dbh.c
@@ -208,10 +208,12 @@ static PHP_METHOD(PDO, dbh_constructor)
zval *options = NULL;
char alt_dsn[512];
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,
&username, &usernamelen, &password, &passwordlen, &options)) {
- ZEND_CTOR_MAKE_NULL();
+ zend_restore_error_handling(&zeh);
return;
}
@@ -224,8 +226,8 @@ static PHP_METHOD(PDO, dbh_constructor)
snprintf(alt_dsn, sizeof(alt_dsn), "pdo.dsn.%s", data_source);
if (FAILURE == cfg_get_string(alt_dsn, &ini_dsn)) {
+ zend_restore_error_handling(&zeh);
zend_throw_exception_ex(php_pdo_get_exception(), 0, "invalid data source name");
- ZEND_CTOR_MAKE_NULL();
return;
}
@@ -233,8 +235,8 @@ static PHP_METHOD(PDO, dbh_constructor)
colon = strchr(data_source, ':');
if (!colon) {
+ zend_restore_error_handling(&zeh);
zend_throw_exception_ex(php_pdo_get_exception(), 0, "invalid data source name (via INI: %s)", alt_dsn);
- ZEND_CTOR_MAKE_NULL();
return;
}
}
@@ -243,14 +245,14 @@ static PHP_METHOD(PDO, dbh_constructor)
/* the specified URI holds connection details */
data_source = dsn_from_uri(data_source + sizeof("uri:")-1, alt_dsn, sizeof(alt_dsn));
if (!data_source) {
+ zend_restore_error_handling(&zeh);
zend_throw_exception_ex(php_pdo_get_exception(), 0, "invalid data source URI");
- ZEND_CTOR_MAKE_NULL();
return;
}
colon = strchr(data_source, ':');
if (!colon) {
+ zend_restore_error_handling(&zeh);
zend_throw_exception_ex(php_pdo_get_exception(), 0, "invalid data source name (via URI)");
- ZEND_CTOR_MAKE_NULL();
return;
}
}
@@ -260,8 +262,8 @@ static PHP_METHOD(PDO, dbh_constructor)
if (!driver) {
/* NB: don't want to include the data_source in the error message as
* it might contain a password */
+ zend_restore_error_handling(&zeh);
zend_throw_exception_ex(php_pdo_get_exception(), 0, "could not find driver");
- ZEND_CTOR_MAKE_NULL();
return;
}
@@ -396,12 +398,16 @@ options:
} ZEND_HASH_FOREACH_END();
}
+ zend_restore_error_handling(&zeh);
return;
}
/* the connection failed; things will tidy up in free_storage */
/* XXX raise exception */
- ZEND_CTOR_MAKE_NULL();
+ zend_restore_error_handling(&zeh);
+ if (!EG(exception)) {
+ zend_throw_exception(pdo_exception_ce, "Constructor failed", 0);
+ }
}
/* }}} */
@@ -459,11 +465,7 @@ static void pdo_stmt_construct(zend_execute_data *execute_data, pdo_stmt_t *stmt
fcc.called_scope = Z_OBJCE_P(object);
fcc.object = Z_OBJ_P(object);
- if (zend_call_function(&fci, &fcc) == FAILURE) {
- Z_OBJ_P(object) = NULL;
- ZEND_CTOR_MAKE_NULL();
- object = NULL; /* marks failure */
- } else if (!Z_ISUNDEF(retval)) {
+ if (zend_call_function(&fci, &fcc) != FAILURE) {
zval_ptr_dtor(&retval);
}
diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c
index c6ebc37ec2..d221c9ed22 100644
--- a/ext/pdo/pdo_stmt.c
+++ b/ext/pdo/pdo_stmt.c
@@ -113,9 +113,9 @@ ZEND_END_ARG_INFO()
RETURN_FALSE; \
} \
-static PHP_FUNCTION(dbstmt_constructor) /* {{{ */
+static PHP_FUNCTION(dbrow_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,7 +2640,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;
- ctor.handler = ZEND_FN(dbstmt_constructor);
+ ctor.handler = ZEND_FN(dbrow_constructor);
ctor.fn_flags = ZEND_ACC_PUBLIC;
return (union _zend_function*)&ctor;
diff --git a/ext/pdo/tests/pdo_036.phpt b/ext/pdo/tests/pdo_036.phpt
index 55c88762ba..a9fdc9315d 100644
--- a/ext/pdo/tests/pdo_036.phpt
+++ b/ext/pdo/tests/pdo_036.phpt
@@ -20,4 +20,9 @@ object(PDOStatement)#%d (1) {
NULL
}
-Fatal error: PDORow::__construct(): You should not create a PDOStatement manually in %spdo_036.php on line %d
+Fatal error: Uncaught exception 'PDOException' with message 'You may not create a PDORow manually' in %spdo_036.php:8
+Stack trace:
+#0 [internal function]: PDORow->__construct()
+#1 %spdo_036.php(8): ReflectionClass->newInstance()
+#2 {main}
+ thrown in %spdo_036.php on line 8
diff --git a/ext/pdo/tests/pdorow.phpt b/ext/pdo/tests/pdorow.phpt
index bcfd8ff229..727f60f2c7 100644
--- a/ext/pdo/tests/pdorow.phpt
+++ b/ext/pdo/tests/pdorow.phpt
@@ -9,4 +9,8 @@ new PDORow;
?>
--EXPECTF--
-Fatal error: PDORow::__construct(): You should not create a PDOStatement manually in %s on line %d
+Fatal error: Uncaught exception 'PDOException' with message 'You may not create a PDORow manually' in %spdorow.php:3
+Stack trace:
+#0 %spdorow.php(3): PDORow->__construct()
+#1 {main}
+ thrown in %spdorow.php on line 3
diff --git a/ext/pdo_mysql/tests/pdo_mysql___construct.phpt b/ext/pdo_mysql/tests/pdo_mysql___construct.phpt
index 0cabfe6aa3..2a890c963d 100644
--- a/ext/pdo_mysql/tests/pdo_mysql___construct.phpt
+++ b/ext/pdo_mysql/tests/pdo_mysql___construct.phpt
@@ -28,8 +28,11 @@ MySQLPDOTest::skip();
try {
- if (NULL !== ($db = @new PDO()))
- printf("[001] Too few parameters\n");
+ try {
+ if (NULL !== ($db = @new PDO()))
+ printf("[001] Too few parameters\n");
+ } catch (Exception $ex) {
+ }
print tryandcatch(2, '$db = new PDO(chr(0));');
print tryandcatch(3, '$db = new PDO("a" . chr(0) . "b");');
diff --git a/ext/pdo_mysql/tests/pdo_mysql___construct_options.phpt b/ext/pdo_mysql/tests/pdo_mysql___construct_options.phpt
index 8cd028fc53..5166958d24 100644
--- a/ext/pdo_mysql/tests/pdo_mysql___construct_options.phpt
+++ b/ext/pdo_mysql/tests/pdo_mysql___construct_options.phpt
@@ -67,8 +67,11 @@ MySQLPDOTest::skip();
PDO::MYSQL_ATTR_INIT_COMMAND => '',
);
- if (NULL !== ($db = @new PDO($dsn, $user, $pass, 'wrong type')))
- printf("[001] Expecting NULL got %s/%s\n", gettype($db), $db);
+ 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) {
+ }
if (!is_object($db = new PDO($dsn, $user, $pass, array())))
printf("[002] Expecting object got %s/%s¸\n", gettype($db), $db);
diff --git a/ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt b/ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt
index 7e92ff2e9a..87a69125bb 100644
--- a/ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt
+++ b/ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt
@@ -68,9 +68,6 @@ MySQLPDOTest::skip();
print "done!";
?>
--EXPECTF--
-Warning: PDO::__construct(%s
[002] URI=uri:file:%spdomuri.tst, DSN=mysql%sdbname=%s, File=%spdomuri.tst (%d bytes, 'mysql%sdbname=%s'), invalid data source URI
-
-Warning: PDO::__construct(%s
[003] URI=uri:file:%spdomuri.tst, DSN=mysql%sdbname=%s, File=%spdomuri.tst (%d bytes, 'mysql%sdbname=letshopeinvalid%s'), chr(0) test, invalid data source URI
done!
diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c
index 67e15c5db9..861f94e763 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/phar/tests/badparameters.phpt b/ext/phar/tests/badparameters.phpt
index 781c8a3f4b..7d5525b887 100644
--- a/ext/phar/tests/badparameters.phpt
+++ b/ext/phar/tests/badparameters.phpt
@@ -7,16 +7,37 @@ phar.readonly=0
--FILE--
<?php
ini_set('phar.readonly', 1);
+
+function print_exception($e) {
+ echo "\nException: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n";
+}
+
Phar::mungServer('hi');
Phar::createDefaultStub(array());
Phar::loadPhar(array());
Phar::canCompress('hi');
-$a = new Phar(array());
-$a = new Phar(dirname(__FILE__) . '/files/frontcontroller10.phar');
+try {
+ $a = new Phar(array());
+} catch (PharException $e) {
+ print_exception($e);
+}
+try {
+ $a = new Phar(dirname(__FILE__) . '/files/frontcontroller10.phar');
+} catch (PharException $e) {
+ print_exception($e);
+}
$a->convertToExecutable(array());
$a->convertToData(array());
-$b = new PharData(dirname(__FILE__) . '/whatever.tar');
-$c = new PharData(dirname(__FILE__) . '/whatever.zip');
+try {
+ $b = new PharData(dirname(__FILE__) . '/whatever.tar');
+} catch (PharException $e) {
+ print_exception($e);
+}
+try {
+ $c = new PharData(dirname(__FILE__) . '/whatever.zip');
+} catch (PharException $e) {
+ print_exception($e);
+}
$b->delete(array());
try {
$a->delete('oops');
@@ -132,7 +153,7 @@ Warning: Phar::loadPhar() expects parameter 1 to be %string, array given in %sba
Warning: Phar::canCompress() expects parameter 1 to be integer, %string given in %sbadparameters.php on line %d
-Warning: Phar::__construct() expects parameter 1 to be %string, array given in %sbadparameters.php on line %d
+Exception: Phar::__construct() expects parameter 1 to be %string, array given in %sbadparameters.php on line %d
Warning: Phar::convertToExecutable() expects parameter 1 to be integer, array given in %sbadparameters.php on line %d
diff --git a/ext/phar/tests/bug60261.phpt b/ext/phar/tests/bug60261.phpt
index 1b6cd7a7cd..c27ff5b554 100644
--- a/ext/phar/tests/bug60261.phpt
+++ b/ext/phar/tests/bug60261.phpt
@@ -14,6 +14,8 @@ try {
?>
--EXPECTF--
-
-Warning: Phar::__construct() expects at least 1 parameter, 0 given in %s on line %d
-SplFileInfo::getLinkTarget(): Empty filename
+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
diff --git a/ext/phar/tests/pharfileinfo_construct.phpt b/ext/phar/tests/pharfileinfo_construct.phpt
index 2610095e6e..df00161d55 100644
--- a/ext/phar/tests/pharfileinfo_construct.phpt
+++ b/ext/phar/tests/pharfileinfo_construct.phpt
@@ -47,8 +47,8 @@ echo $e->getMessage() . "\n";
--EXPECTF--
Cannot open phar file 'phar://%spharfileinfo_construct.phar/oops': internal corruption of phar "%spharfileinfo_construct.phar" (truncated entry)
-Warning: PharFileInfo::__construct() expects parameter 1 to be %string, array given in %spharfileinfo_construct.php on line %d
-Cannot access phar file entry '/oops/I/do/not/exist' in archive '%spharfileinfo_construct.phar'
-Cannot call constructor twice
-'%spharfileinfo_construct.php' is not a valid phar archive URL (must have at least phar://filename.phar)
-===DONE=== \ No newline at end of file
+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
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index e78410ec71..4dc0ed6868 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