Patch improvement:

Removed the corresponding core code.
Fixed ext/com_dotnet and ext/date.
Refactored ext/intl changes.
Improved ext/fileinfo and ext/pdo changes.
Fixed tests.
This commit is contained in:
Dmitry Stogov 2015-03-30 18:53:38 +03:00
parent 9155a267ad
commit 1018f462d8
50 changed files with 509 additions and 506 deletions

View file

@ -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) /* {{{ */ ZEND_API const char *zend_get_object_type(const zend_class_entry *ce) /* {{{ */
{ {
if(ce->ce_flags & ZEND_ACC_TRAIT) { if(ce->ce_flags & ZEND_ACC_TRAIT) {

View file

@ -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_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 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); 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)) #define add_method(arg, key, method) add_assoc_function((arg), (key), (method))
@ -651,10 +649,6 @@ END_EXTERN_C()
} \ } \
} while (0) } 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 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))) #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)))

View file

@ -2950,10 +2950,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, EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call)); fbc, opline->extended_value, ce, object, EX(call));
if (OP2_TYPE == IS_UNUSED) {
EX(call)->return_value = NULL;
}
CHECK_EXCEPTION(); CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE(); ZEND_VM_NEXT_OPCODE();
} }
@ -4704,9 +4700,6 @@ ZEND_VM_HANDLER(68, ZEND_NEW, CONST|VAR, ANY)
if (EXPECTED(RETURN_VALUE_USED(opline))) { if (EXPECTED(RETURN_VALUE_USED(opline))) {
ZVAL_COPY(EX_VAR(opline->result.var), &object_zval); 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(); CHECK_EXCEPTION();

View file

@ -3100,9 +3100,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_NEW_SPEC_CONST_HANDLER(ZEND_OP
if (EXPECTED(RETURN_VALUE_USED(opline))) { if (EXPECTED(RETURN_VALUE_USED(opline))) {
ZVAL_COPY(EX_VAR(opline->result.var), &object_zval); 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(); CHECK_EXCEPTION();
@ -5082,10 +5079,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, EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call)); fbc, opline->extended_value, ce, object, EX(call));
if (IS_CONST == IS_UNUSED) {
EX(call)->return_value = NULL;
}
CHECK_EXCEPTION(); CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE(); ZEND_VM_NEXT_OPCODE();
} }
@ -6984,10 +6977,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, EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call)); fbc, opline->extended_value, ce, object, EX(call));
if (IS_UNUSED == IS_UNUSED) {
EX(call)->return_value = NULL;
}
CHECK_EXCEPTION(); CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE(); ZEND_VM_NEXT_OPCODE();
} }
@ -8466,10 +8455,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, EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call)); fbc, opline->extended_value, ce, object, EX(call));
if (IS_CV == IS_UNUSED) {
EX(call)->return_value = NULL;
}
CHECK_EXCEPTION(); CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE(); ZEND_VM_NEXT_OPCODE();
} }
@ -10015,10 +10000,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, EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call)); fbc, opline->extended_value, ce, object, EX(call));
if ((IS_TMP_VAR|IS_VAR) == IS_UNUSED) {
EX(call)->return_value = NULL;
}
CHECK_EXCEPTION(); CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE(); ZEND_VM_NEXT_OPCODE();
} }
@ -13795,9 +13776,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_NEW_SPEC_VAR_HANDLER(ZEND_OPCO
if (EXPECTED(RETURN_VALUE_USED(opline))) { if (EXPECTED(RETURN_VALUE_USED(opline))) {
ZVAL_COPY(EX_VAR(opline->result.var), &object_zval); 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(); CHECK_EXCEPTION();
@ -15880,10 +15858,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, EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call)); fbc, opline->extended_value, ce, object, EX(call));
if (IS_CONST == IS_UNUSED) {
EX(call)->return_value = NULL;
}
CHECK_EXCEPTION(); CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE(); ZEND_VM_NEXT_OPCODE();
} }
@ -17455,10 +17429,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, EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call)); fbc, opline->extended_value, ce, object, EX(call));
if (IS_UNUSED == IS_UNUSED) {
EX(call)->return_value = NULL;
}
CHECK_EXCEPTION(); CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE(); ZEND_VM_NEXT_OPCODE();
} }
@ -19072,10 +19042,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, EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call)); fbc, opline->extended_value, ce, object, EX(call));
if (IS_CV == IS_UNUSED) {
EX(call)->return_value = NULL;
}
CHECK_EXCEPTION(); CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE(); ZEND_VM_NEXT_OPCODE();
} }
@ -20631,10 +20597,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, EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call)); fbc, opline->extended_value, ce, object, EX(call));
if ((IS_TMP_VAR|IS_VAR) == IS_UNUSED) {
EX(call)->return_value = NULL;
}
CHECK_EXCEPTION(); CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE(); ZEND_VM_NEXT_OPCODE();
} }

View file

@ -66,7 +66,6 @@ PHP_FUNCTION(com_create_instance)
&typelib_name, &typelib_name_len)) { &typelib_name, &typelib_name_len)) {
php_com_throw_exception(E_INVALIDARG, "Could not create COM object - invalid arguments!"); php_com_throw_exception(E_INVALIDARG, "Could not create COM object - invalid arguments!");
ZEND_CTOR_MAKE_NULL();
return; return;
} }
@ -230,7 +229,6 @@ PHP_FUNCTION(com_create_instance)
php_com_throw_exception(res, msg); php_com_throw_exception(res, msg);
efree(msg); efree(msg);
ZEND_CTOR_MAKE_NULL();
return; return;
} }

View file

@ -208,7 +208,6 @@ PHP_FUNCTION(com_dotnet_create_instance)
if (err) if (err)
LocalFree(err); LocalFree(err);
php_com_throw_exception(hr, buf); php_com_throw_exception(hr, buf);
ZEND_CTOR_MAKE_NULL();
return; return;
} }
stuff = (struct dotnet_runtime_stuff*)COMG(dotnet_runtime_stuff); stuff = (struct dotnet_runtime_stuff*)COMG(dotnet_runtime_stuff);
@ -248,7 +247,6 @@ PHP_FUNCTION(com_dotnet_create_instance)
&datatype_name, &datatype_name_len, &datatype_name, &datatype_name_len,
&obj->code_page)) { &obj->code_page)) {
php_com_throw_exception(E_INVALIDARG, "Could not create .Net object - invalid arguments!"); php_com_throw_exception(E_INVALIDARG, "Could not create .Net object - invalid arguments!");
ZEND_CTOR_MAKE_NULL();
return; return;
} }
@ -314,7 +312,6 @@ PHP_FUNCTION(com_dotnet_create_instance)
LocalFree(err); LocalFree(err);
} }
php_com_throw_exception(hr, buf); php_com_throw_exception(hr, buf);
ZEND_CTOR_MAKE_NULL();
return; return;
} }
} }

View file

@ -2670,9 +2670,7 @@ PHP_METHOD(DateTime, __construct)
zend_replace_error_handling(EH_THROW, NULL, &error_handling); zend_replace_error_handling(EH_THROW, NULL, &error_handling);
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|sO!", &time_str, &time_str_len, &timezone_object, date_ce_timezone)) { 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)) { php_date_initialize(Z_PHPDATE_P(getThis()), time_str, time_str_len, NULL, timezone_object, 1);
ZEND_CTOR_MAKE_NULL();
}
} }
zend_restore_error_handling(&error_handling); zend_restore_error_handling(&error_handling);
} }
@ -3679,9 +3677,7 @@ PHP_METHOD(DateTimeZone, __construct)
zend_replace_error_handling(EH_THROW, NULL, &error_handling); zend_replace_error_handling(EH_THROW, NULL, &error_handling);
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &tz, &tz_len)) { if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &tz, &tz_len)) {
tzobj = Z_PHPTIMEZONE_P(getThis()); tzobj = Z_PHPTIMEZONE_P(getThis());
if (FAILURE == timezone_initialize(tzobj, tz)) { timezone_initialize(tzobj, tz);
ZEND_CTOR_MAKE_NULL();
}
} }
zend_restore_error_handling(&error_handling); zend_restore_error_handling(&error_handling);
} }
@ -4113,8 +4109,6 @@ PHP_METHOD(DateInterval, __construct)
diobj = Z_PHPINTERVAL_P(getThis()); diobj = Z_PHPINTERVAL_P(getThis());
diobj->diff = reltime; diobj->diff = reltime;
diobj->initialized = 1; diobj->initialized = 1;
} else {
ZEND_CTOR_MAKE_NULL();
} }
} }
zend_restore_error_handling(&error_handling); zend_restore_error_handling(&error_handling);

View file

@ -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]]) /* {{{ proto resource finfo_open([int options [, string arg]])
Create a new fileinfo resource. */ Create a new fileinfo resource. */
PHP_FUNCTION(finfo_open) PHP_FUNCTION(finfo_open)
@ -302,18 +293,17 @@ PHP_FUNCTION(finfo_open)
FILEINFO_DECLARE_INIT_OBJECT(object) FILEINFO_DECLARE_INIT_OBJECT(object)
char resolved_path[MAXPATHLEN]; char resolved_path[MAXPATHLEN];
zend_error_handling zeh; zend_error_handling zeh;
int rv;
if (object) { if (object) {
zend_replace_error_handling(EH_THROW, NULL, &zeh TSRMLS_CC); zend_replace_error_handling(EH_THROW, NULL, &zeh);
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 (zend_parse_parameters(ZEND_NUM_ARGS(), "|lp", &options, &file, &file_len) == FAILURE) {
if (rv == FAILURE) { if (object) {
FILEINFO_DESTROY_OBJECT(object); zend_restore_error_handling(&zeh);
if (!EG(exception)) {
zend_throw_exception(NULL, "Constructor failed", 0);
}
}
RETURN_FALSE; RETURN_FALSE;
} }
@ -332,11 +322,21 @@ PHP_FUNCTION(finfo_open)
} else if (file && *file) { /* user specified file, perform open_basedir checks */ } else if (file && *file) { /* user specified file, perform open_basedir checks */
if (php_check_open_basedir(file)) { 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; RETURN_FALSE;
} }
if (!expand_filepath_with_mode(file, resolved_path, NULL, 0, CWD_EXPAND)) { 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; RETURN_FALSE;
} }
file = resolved_path; file = resolved_path;
@ -350,7 +350,12 @@ PHP_FUNCTION(finfo_open)
if (finfo->magic == NULL) { if (finfo->magic == NULL) {
efree(finfo); efree(finfo);
php_error_docref(NULL, E_WARNING, "Invalid mode '%pd'.", options); 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; RETURN_FALSE;
} }
@ -358,11 +363,17 @@ PHP_FUNCTION(finfo_open)
php_error_docref(NULL, E_WARNING, "Failed to load magic database at '%s'.", file); php_error_docref(NULL, E_WARNING, "Failed to load magic database at '%s'.", file);
magic_close(finfo->magic); magic_close(finfo->magic);
efree(finfo); 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; RETURN_FALSE;
} }
if (object) { if (object) {
zend_restore_error_handling(&zeh);
FILEINFO_REGISTER_OBJECT(object, finfo); FILEINFO_REGISTER_OBJECT(object, finfo);
} else { } else {
RETURN_RES(zend_register_resource(finfo, le_fileinfo)); RETURN_RES(zend_register_resource(finfo, le_fileinfo));

View file

@ -10,5 +10,8 @@ if (!class_exists('finfo'))
$finfo = new finfo(1, '', false); $finfo = new finfo(1, '', false);
var_dump($finfo); var_dump($finfo);
--EXPECTF-- --EXPECTF--
Warning: finfo::finfo() expects at most 2 parameters, 3 given in %s on line %d Fatal error: Uncaught exception 'Exception' with message 'finfo::finfo() expects at most 2 parameters, 3 given' in %sbug61173.php:3
NULL Stack trace:
#0 %sbug61173.php(3): finfo->finfo(1, '', false)
#1 {main}
thrown in %sbug61173.php on line 3

View file

@ -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 Warning: finfo_open() expects parameter 1 to be integer, string given in %sfinfo_open_error.php on line 16
bool(false) bool(false)
Warning: finfo::finfo() expects parameter 1 to be integer, string given in %sfinfo_open_error.php on line 18 Fatal error: Uncaught exception 'Exception' with message 'finfo::finfo() expects parameter 1 to be integer, string given' in %sfinfo_open_error.php:18
NULL Stack trace:
===DONE=== #0 %sfinfo_open_error.php(18): finfo->finfo('foobar')
#1 {main}
thrown in %sfinfo_open_error.php on line 18

View file

@ -162,12 +162,12 @@ U_CFUNC PHP_FUNCTION(breakiter_set_text)
BREAKITER_METHOD_FETCH_OBJECT; BREAKITER_METHOD_FETCH_OBJECT;
ut = utext_openUTF8(ut, text->val, text->len, BREAKITER_ERROR_CODE_P(bio)); ut = utext_openUTF8(ut, text->val, text->len, BREAKITER_ERROR_CODE_P(bio));
INTL_CTOR_CHECK_STATUS(bio, "breakiter_set_text: error opening UText", 0); INTL_CTOR_CHECK_STATUS(bio, "breakiter_set_text: error opening UText");
bio->biter->setText(ut, BREAKITER_ERROR_CODE(bio)); bio->biter->setText(ut, BREAKITER_ERROR_CODE(bio));
utext_close(ut); /* ICU shallow clones the UText */ utext_close(ut); /* ICU shallow clones the UText */
INTL_CTOR_CHECK_STATUS(bio, "breakiter_set_text: error calling " INTL_CTOR_CHECK_STATUS(bio, "breakiter_set_text: error calling "
"BreakIterator::setText()", 0); "BreakIterator::setText()");
/* When ICU clones the UText, it does not copy the buffer, so we have to /* 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 * keep the string buffer around by holding a reference to its zval. This

View file

@ -24,6 +24,7 @@ extern "C" {
} }
#include "../intl_convertcpp.h" #include "../intl_convertcpp.h"
#include "../intl_common.h"
static inline RuleBasedBreakIterator *fetch_rbbi(BreakIterator_object *bio) { static inline RuleBasedBreakIterator *fetch_rbbi(BreakIterator_object *bio) {
return (RuleBasedBreakIterator*)bio->biter; return (RuleBasedBreakIterator*)bio->biter;
@ -97,15 +98,17 @@ static void _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
U_CFUNC PHP_METHOD(IntlRuleBasedBreakIterator, __construct) 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(); return_value = getThis();
_php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU); _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU);
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
zend_object_store_ctor_failed(Z_OBJ(orig_this)); if (!EG(exception)) {
ZEND_CTOR_MAKE_NULL(); zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
}
} }
zend_restore_error_handling(&error_handling);
} }
U_CFUNC PHP_FUNCTION(rbbi_get_rules) U_CFUNC PHP_FUNCTION(rbbi_get_rules)

View file

@ -25,18 +25,20 @@
#include <unicode/gregocal.h> #include <unicode/gregocal.h>
extern "C" { extern "C" {
#include "../php_intl.h" #include "../php_intl.h"
#include "../intl_common.h"
#define USE_TIMEZONE_POINTER 1 #define USE_TIMEZONE_POINTER 1
#include "../timezone/timezone_class.h" #include "../timezone/timezone_class.h"
#define USE_CALENDAR_POINTER 1 #define USE_CALENDAR_POINTER 1
#include "calendar_class.h" #include "calendar_class.h"
#include <ext/date/php_date.h> #include <ext/date/php_date.h>
#include "zend_exceptions.h"
} }
static inline GregorianCalendar *fetch_greg(Calendar_object *co) { static inline GregorianCalendar *fetch_greg(Calendar_object *co) {
return (GregorianCalendar*)co->ucal; return (GregorianCalendar*)co->ucal;
} }
static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
{ {
zval *tz_object = NULL; zval *tz_object = NULL;
zval args_a[6] = {0}, zval args_a[6] = {0},
@ -51,8 +53,8 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS, zend
// parameter number validation / variant determination // parameter number validation / variant determination
if (ZEND_NUM_ARGS() > 6 || if (ZEND_NUM_ARGS() > 6 ||
zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) { zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) {
intl_error_set_ex(NULL, U_ILLEGAL_ARGUMENT_ERROR, intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"intlgregcal_create_instance: too many arguments", 0, is_constructor); "intlgregcal_create_instance: too many arguments", 0);
Z_OBJ_P(return_value) = NULL; Z_OBJ_P(return_value) = NULL;
return; return;
} }
@ -60,9 +62,9 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS, zend
variant > 0 && Z_TYPE(args[variant - 1]) == IS_NULL; variant > 0 && Z_TYPE(args[variant - 1]) == IS_NULL;
variant--) {} variant--) {}
if (variant == 4) { if (variant == 4) {
intl_error_set_ex(NULL, U_ILLEGAL_ARGUMENT_ERROR, intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"intlgregcal_create_instance: no variant with 4 arguments " "intlgregcal_create_instance: no variant with 4 arguments "
"(excluding trailing NULLs)", 0, is_constructor); "(excluding trailing NULLs)", 0);
Z_OBJ_P(return_value) = NULL; Z_OBJ_P(return_value) = NULL;
return; return;
} }
@ -71,8 +73,8 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS, zend
if (variant <= 2) { if (variant <= 2) {
if (zend_parse_parameters(MIN(ZEND_NUM_ARGS(), 2), if (zend_parse_parameters(MIN(ZEND_NUM_ARGS(), 2),
"|z!s!", &tz_object, &locale, &locale_len) == FAILURE) { "|z!s!", &tz_object, &locale, &locale_len) == FAILURE) {
intl_error_set_ex(NULL, U_ILLEGAL_ARGUMENT_ERROR, intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"intlgregcal_create_instance: bad arguments", 0, is_constructor); "intlgregcal_create_instance: bad arguments", 0);
Z_OBJ_P(return_value) = NULL; Z_OBJ_P(return_value) = NULL;
return; return;
} }
@ -80,8 +82,8 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS, zend
if (variant > 2 && zend_parse_parameters(ZEND_NUM_ARGS(), if (variant > 2 && zend_parse_parameters(ZEND_NUM_ARGS(),
"lll|lll", &largs[0], &largs[1], &largs[2], &largs[3], &largs[4], "lll|lll", &largs[0], &largs[1], &largs[2], &largs[3], &largs[4],
&largs[5]) == FAILURE) { &largs[5]) == FAILURE) {
intl_error_set_ex(NULL, U_ILLEGAL_ARGUMENT_ERROR, intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"intlgregcal_create_instance: bad arguments", 0, is_constructor); "intlgregcal_create_instance: bad arguments", 0);
Z_OBJ_P(return_value) = NULL; Z_OBJ_P(return_value) = NULL;
return; return;
} }
@ -104,8 +106,8 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS, zend
gcal = new GregorianCalendar(tz, Locale::createFromName(locale), gcal = new GregorianCalendar(tz, Locale::createFromName(locale),
status); status);
if (U_FAILURE(status)) { if (U_FAILURE(status)) {
intl_error_set_ex(NULL, status, "intlgregcal_create_instance: error " intl_error_set(NULL, status, "intlgregcal_create_instance: error "
"creating ICU GregorianCalendar from time zone and locale", 0, is_constructor); "creating ICU GregorianCalendar from time zone and locale", 0);
if (gcal) { if (gcal) {
delete gcal; delete gcal;
} }
@ -117,9 +119,9 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS, zend
// From date/time (3, 5 or 6 arguments) // From date/time (3, 5 or 6 arguments)
for (int i = 0; i < variant; i++) { for (int i = 0; i < variant; i++) {
if (largs[i] < INT32_MIN || largs[i] > INT32_MAX) { if (largs[i] < INT32_MIN || largs[i] > INT32_MAX) {
intl_error_set_ex(NULL, U_ILLEGAL_ARGUMENT_ERROR, intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"intlgregcal_create_instance: at least one of the arguments" "intlgregcal_create_instance: at least one of the arguments"
" has an absolute value that is too large", 0, is_constructor); " has an absolute value that is too large", 0);
Z_OBJ_P(return_value) = NULL; Z_OBJ_P(return_value) = NULL;
return; return;
} }
@ -137,8 +139,8 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS, zend
status); status);
} }
if (U_FAILURE(status)) { if (U_FAILURE(status)) {
intl_error_set_ex(NULL, status, "intlgregcal_create_instance: error " intl_error_set(NULL, status, "intlgregcal_create_instance: error "
"creating ICU GregorianCalendar from date", 0, is_constructor); "creating ICU GregorianCalendar from date", 0);
if (gcal) { if (gcal) {
delete gcal; delete gcal;
} }
@ -154,10 +156,10 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS, zend
strlen(tzinfo->name), US_INV); strlen(tzinfo->name), US_INV);
#endif #endif
if (tzstr.isBogus()) { if (tzstr.isBogus()) {
intl_error_set_ex(NULL, U_ILLEGAL_ARGUMENT_ERROR, intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"intlgregcal_create_instance: could not create UTF-8 string " "intlgregcal_create_instance: could not create UTF-8 string "
"from PHP's default timezone name (see date_default_timezone_get())", "from PHP's default timezone name (see date_default_timezone_get())",
0, is_constructor); 0);
delete gcal; delete gcal;
Z_OBJ_P(return_value) = NULL; Z_OBJ_P(return_value) = NULL;
return; return;
@ -179,7 +181,7 @@ U_CFUNC PHP_FUNCTION(intlgregcal_create_instance)
object_init_ex(return_value, GregorianCalendar_ce_ptr); object_init_ex(return_value, GregorianCalendar_ce_ptr);
ZVAL_COPY_VALUE(&orig, return_value); ZVAL_COPY_VALUE(&orig, return_value);
_php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU);
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
zval_dtor(&orig); zval_dtor(&orig);
@ -189,17 +191,18 @@ U_CFUNC PHP_FUNCTION(intlgregcal_create_instance)
U_CFUNC PHP_METHOD(IntlGregorianCalendar, __construct) U_CFUNC PHP_METHOD(IntlGregorianCalendar, __construct)
{ {
zval orig_this = *getThis(); zend_error_handling error_handling;
intl_error_reset(NULL);
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
return_value = getThis(); return_value = getThis();
//changes this to IS_NULL (without first destroying) if there's an error //changes this to IS_NULL (without first destroying) if there's an error
_php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU);
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
zend_object_store_ctor_failed(Z_OBJ(orig_this)); if (!EG(exception)) {
ZEND_CTOR_MAKE_NULL(); zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
}
} }
zend_restore_error_handling(&error_handling);
} }
U_CFUNC PHP_FUNCTION(intlgregcal_set_gregorian_change) U_CFUNC PHP_FUNCTION(intlgregcal_set_gregorian_change)

View file

@ -25,7 +25,7 @@
#include "intl_data.h" #include "intl_data.h"
/* {{{ */ /* {{{ */
static void collator_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) static void collator_ctor(INTERNAL_FUNCTION_PARAMETERS)
{ {
const char* locale; const char* locale;
size_t locale_len = 0; size_t locale_len = 0;
@ -38,8 +38,8 @@ static void collator_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor
if( zend_parse_parameters( ZEND_NUM_ARGS(), "s", if( zend_parse_parameters( ZEND_NUM_ARGS(), "s",
&locale, &locale_len ) == FAILURE ) &locale, &locale_len ) == FAILURE )
{ {
intl_error_set_ex( NULL, U_ILLEGAL_ARGUMENT_ERROR, intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
"collator_create: unable to parse input params", 0, is_constructor ); "collator_create: unable to parse input params", 0 );
zval_dtor(return_value); zval_dtor(return_value);
RETURN_NULL(); RETURN_NULL();
} }
@ -53,7 +53,7 @@ static void collator_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor
/* Open ICU collator. */ /* Open ICU collator. */
co->ucoll = ucol_open( locale, COLLATOR_ERROR_CODE_P( co ) ); co->ucoll = ucol_open( locale, COLLATOR_ERROR_CODE_P( co ) );
INTL_CTOR_CHECK_STATUS(co, "collator_create: unable to open ICU collator", is_constructor); INTL_CTOR_CHECK_STATUS(co, "collator_create: unable to open ICU collator");
} }
/* }}} */ /* }}} */
@ -63,7 +63,7 @@ static void collator_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor
PHP_FUNCTION( collator_create ) PHP_FUNCTION( collator_create )
{ {
object_init_ex( return_value, Collator_ce_ptr ); object_init_ex( return_value, Collator_ce_ptr );
collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
} }
/* }}} */ /* }}} */
@ -72,15 +72,17 @@ PHP_FUNCTION( collator_create )
*/ */
PHP_METHOD( Collator, __construct ) 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(); return_value = getThis();
collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
zend_object_store_ctor_failed(Z_OBJ(orig_this)); if (!EG(exception)) {
ZEND_CTOR_MAKE_NULL(); zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
}
} }
zend_restore_error_handling(&error_handling);
} }
/* }}} */ /* }}} */

View file

@ -562,10 +562,10 @@ static PHP_METHOD(UConverter, __construct) {
intl_error_reset(NULL); intl_error_reset(NULL);
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &zeh TSRMLS_CC); zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &zeh);
rv = zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s!", rv = zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s!",
&dest, &dest_len, &src, &src_len); &dest, &dest_len, &src, &src_len);
zend_restore_error_handling(&zeh TSRMLS_CC); zend_restore_error_handling(&zeh);
if (rv == FAILURE) { if (rv == FAILURE) {
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,

View file

@ -34,9 +34,10 @@ extern "C" {
} }
#include "dateformat_helpers.h" #include "dateformat_helpers.h"
#include "zend_exceptions.h"
/* {{{ */ /* {{{ */
static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
{ {
zval *object; zval *object;
@ -64,8 +65,8 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor)
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sll|zzs", if (zend_parse_parameters(ZEND_NUM_ARGS(), "sll|zzs",
&locale_str, &locale_len, &date_type, &time_type, &timezone_zv, &locale_str, &locale_len, &date_type, &time_type, &timezone_zv,
&calendar_zv, &pattern_str, &pattern_str_len) == FAILURE) { &calendar_zv, &pattern_str, &pattern_str_len) == FAILURE) {
intl_error_set_ex( NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: " intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: "
"unable to parse input parameters", 0, is_constructor); "unable to parse input parameters", 0);
Z_OBJ_P(return_value) = NULL; Z_OBJ_P(return_value) = NULL;
return; return;
} }
@ -79,8 +80,6 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor)
DATE_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK; DATE_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK;
if (DATE_FORMAT_OBJECT(dfo) != NULL) { 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, intl_errors_set(INTL_DATA_ERROR_P(dfo), U_ILLEGAL_ARGUMENT_ERROR,
"datefmt_create: cannot call constructor twice", 0); "datefmt_create: cannot call constructor twice", 0);
return; return;
@ -112,8 +111,8 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor)
pattern_str, pattern_str_len, &INTL_DATA_ERROR_CODE(dfo)); pattern_str, pattern_str_len, &INTL_DATA_ERROR_CODE(dfo));
if (U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) { if (U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) {
/* object construction -> only set global error */ /* object construction -> only set global error */
intl_error_set_ex(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create: " intl_error_set(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create: "
"error converting pattern to UTF-16", 0, is_constructor); "error converting pattern to UTF-16", 0);
goto error; goto error;
} }
} }
@ -141,8 +140,8 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor)
df->adoptTimeZone(timezone); df->adoptTimeZone(timezone);
} }
} else { } else {
intl_error_set_ex(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create: date " intl_error_set(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create: date "
"formatter creation failed", 0, is_constructor); "formatter creation failed", 0);
goto error; goto error;
} }
@ -177,7 +176,7 @@ error:
U_CFUNC PHP_FUNCTION( datefmt_create ) U_CFUNC PHP_FUNCTION( datefmt_create )
{ {
object_init_ex( return_value, IntlDateFormatter_ce_ptr ); object_init_ex( return_value, IntlDateFormatter_ce_ptr );
datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
RETURN_NULL(); RETURN_NULL();
} }
@ -189,16 +188,18 @@ U_CFUNC PHP_FUNCTION( datefmt_create )
*/ */
U_CFUNC PHP_METHOD( IntlDateFormatter, __construct ) 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 /* return_value param is being changed, therefore we will always return
* NULL here */ * NULL here */
return_value = getThis(); return_value = getThis();
datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
zend_object_store_ctor_failed(Z_OBJ(orig_this)); if (!EG(exception)) {
ZEND_CTOR_MAKE_NULL(); zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
}
} }
zend_restore_error_handling(&error_handling);
} }
/* }}} */ /* }}} */

View file

@ -25,7 +25,7 @@
#include "intl_convert.h" #include "intl_convert.h"
/* {{{ */ /* {{{ */
static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
{ {
const char* locale; const char* locale;
char* pattern = NULL; char* pattern = NULL;
@ -39,8 +39,8 @@ static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor)
if( zend_parse_parameters( ZEND_NUM_ARGS(), "sl|s", if( zend_parse_parameters( ZEND_NUM_ARGS(), "sl|s",
&locale, &locale_len, &style, &pattern, &pattern_len ) == FAILURE ) &locale, &locale_len, &style, &pattern, &pattern_len ) == FAILURE )
{ {
intl_error_set_ex( NULL, U_ILLEGAL_ARGUMENT_ERROR, intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
"numfmt_create: unable to parse input parameters", 0, is_constructor ); "numfmt_create: unable to parse input parameters", 0 );
Z_OBJ_P(return_value) = NULL; Z_OBJ_P(return_value) = NULL;
return; return;
} }
@ -52,7 +52,7 @@ static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor)
/* Convert pattern (if specified) to UTF-16. */ /* Convert pattern (if specified) to UTF-16. */
if(pattern && pattern_len) { if(pattern && pattern_len) {
intl_convert_utf8_to_utf16(&spattern, &spattern_len, pattern, pattern_len, &INTL_DATA_ERROR_CODE(nfo)); 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", is_constructor); INTL_CTOR_CHECK_STATUS(nfo, "numfmt_create: error converting pattern to UTF-16");
} }
if(locale_len == 0) { if(locale_len == 0) {
@ -66,7 +66,7 @@ static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor)
efree(spattern); efree(spattern);
} }
INTL_CTOR_CHECK_STATUS(nfo, "numfmt_create: number formatter creation failed", is_constructor); INTL_CTOR_CHECK_STATUS(nfo, "numfmt_create: number formatter creation failed");
} }
/* }}} */ /* }}} */
@ -78,7 +78,7 @@ static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor)
PHP_FUNCTION( numfmt_create ) PHP_FUNCTION( numfmt_create )
{ {
object_init_ex( return_value, NumberFormatter_ce_ptr ); object_init_ex( return_value, NumberFormatter_ce_ptr );
numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
RETURN_NULL(); RETURN_NULL();
} }
@ -90,15 +90,17 @@ PHP_FUNCTION( numfmt_create )
*/ */
PHP_METHOD( NumberFormatter, __construct ) 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(); return_value = getThis();
numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
zend_object_store_ctor_failed(Z_OBJ(orig_this)); if (!EG(exception)) {
ZEND_CTOR_MAKE_NULL(); zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
}
} }
zend_restore_error_handling(&error_handling);
} }
/* }}} */ /* }}} */

View file

@ -64,11 +64,11 @@ typedef struct _intl_data {
} }
/* Check status, if error - destroy value and exit */ /* Check status, if error - destroy value and exit */
#define INTL_CTOR_CHECK_STATUS(obj, msg, forceException) \ #define INTL_CTOR_CHECK_STATUS(obj, msg) \
intl_error_set_code( NULL, INTL_DATA_ERROR_CODE((obj)) ); \ intl_error_set_code( NULL, INTL_DATA_ERROR_CODE((obj)) ); \
if( U_FAILURE( INTL_DATA_ERROR_CODE((obj)) ) ) \ if( U_FAILURE( INTL_DATA_ERROR_CODE((obj)) ) ) \
{ \ { \
intl_errors_set_custom_msg_ex( INTL_DATA_ERROR_P((obj)), msg, 0, forceException ); \ intl_errors_set_custom_msg( INTL_DATA_ERROR_P((obj)), msg, 0 ); \
/* yes, this is ugly, but it alreay is */ \ /* yes, this is ugly, but it alreay is */ \
if (return_value != getThis()) { \ if (return_value != getThis()) { \
zval_dtor(return_value); \ zval_dtor(return_value); \

View file

@ -102,26 +102,15 @@ void intl_error_reset( intl_error* err )
* Set last error message to msg copying it if needed. * Set last error message to msg copying it if needed.
*/ */
void intl_error_set_custom_msg( intl_error* err, char* msg, int copyMsg ) void intl_error_set_custom_msg( intl_error* err, 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 ) if( !msg )
return; return;
if( !err ) { if( !err ) {
if ( forceException || INTL_G( use_exceptions ) ) { if( INTL_G( error_level ) )
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 ); php_error_docref( NULL, INTL_G( error_level ), "%s", msg );
} if( INTL_G( use_exceptions ) )
zend_throw_exception_ex( IntlException_ce_ptr, 0, "%s", msg );
} }
if( !err && !( err = intl_g_error_get( ) ) ) if( !err && !( err = intl_g_error_get( ) ) )
return; return;
@ -192,39 +181,19 @@ UErrorCode intl_error_get_code( intl_error* err )
* Set error code and message. * Set error code and message.
*/ */
void intl_error_set( intl_error* err, UErrorCode code, char* msg, int copyMsg ) void intl_error_set( intl_error* err, UErrorCode code, 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_code( err, code );
intl_error_set_custom_msg_ex( err, msg, copyMsg, forceException ); intl_error_set_custom_msg( err, msg, copyMsg );
} }
/* }}} */ /* }}} */
/* {{{ void intl_errors_set( intl_error* err, UErrorCode code, char* msg, int copyMsg ) /* {{{ void intl_errors_set( intl_error* err, UErrorCode code, char* msg, int copyMsg )
* Set error code and message. * Set error code and message.
*/ */
void intl_errors_set( intl_error* err, UErrorCode code, char* msg, int copyMsg ) void intl_errors_set( intl_error* err, UErrorCode code, 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_code( err, code );
intl_errors_set_custom_msg_ex( err, msg, copyMsg, forceException ); intl_errors_set_custom_msg( err, msg, copyMsg );
} }
/* }}} */ /* }}} */
@ -242,24 +211,14 @@ void intl_errors_reset( intl_error* err )
/* {{{ void intl_errors_set_custom_msg( intl_error* err, char* msg, int copyMsg ) /* {{{ void intl_errors_set_custom_msg( intl_error* err, char* msg, int copyMsg )
*/ */
void intl_errors_set_custom_msg( intl_error* err, char* msg, int copyMsg ) 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) { if(err) {
intl_error_set_custom_msg_ex( err, msg, copyMsg, forceException ); intl_error_set_custom_msg( err, msg, copyMsg );
} }
intl_error_set_custom_msg_ex( NULL, msg, copyMsg, forceException ); intl_error_set_custom_msg( NULL, msg, copyMsg );
} }
/* }}} */ /* }}} */
/* {{{ intl_errors_set_code( intl_error* err, UErrorCode err_code ) /* {{{ intl_errors_set_code( intl_error* err, UErrorCode err_code )
*/ */
void intl_errors_set_code( intl_error* err, UErrorCode err_code ) void intl_errors_set_code( intl_error* err, UErrorCode err_code )

View file

@ -36,21 +36,15 @@ void intl_error_init( intl_error* err );
void intl_error_reset( 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_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( 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( 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 ); UErrorCode intl_error_get_code( intl_error* err );
zend_string* intl_error_get_message( intl_error* err ); zend_string* intl_error_get_message( intl_error* err );
// Wrappers to synchonize object's and global error structures. // Wrappers to synchonize object's and global error structures.
void intl_errors_reset( intl_error* err ); void intl_errors_reset( intl_error* err );
void intl_errors_set_custom_msg( intl_error* err, char* msg, int copyMsg ); void intl_errors_set_custom_msg( intl_error* err, char* msg, int copyMsg );
void intl_errors_set_custom_msg_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_code( intl_error* err, UErrorCode err_code );
void intl_errors_set( intl_error* err, UErrorCode code, char* msg, int copyMsg ); void intl_errors_set( intl_error* err, UErrorCode code, char* msg, int copyMsg );
void intl_errors_set_ex( intl_error* err, UErrorCode code, char* msg, int copyMsg, int forceException );
// Other error helpers // Other error helpers
smart_str intl_parse_error_to_string( UParseError* pe ); smart_str intl_parse_error_to_string( UParseError* pe );

View file

@ -26,7 +26,7 @@
#include "intl_convert.h" #include "intl_convert.h"
/* {{{ */ /* {{{ */
static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
{ {
const char* locale; const char* locale;
char* pattern; char* pattern;
@ -42,8 +42,8 @@ static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor)
if( zend_parse_parameters( ZEND_NUM_ARGS(), "ss", if( zend_parse_parameters( ZEND_NUM_ARGS(), "ss",
&locale, &locale_len, &pattern, &pattern_len ) == FAILURE ) &locale, &locale_len, &pattern, &pattern_len ) == FAILURE )
{ {
intl_error_set_ex( NULL, U_ILLEGAL_ARGUMENT_ERROR, intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
"msgfmt_create: unable to parse input parameters", 0, is_constructor ); "msgfmt_create: unable to parse input parameters", 0 );
Z_OBJ_P(return_value) = NULL; Z_OBJ_P(return_value) = NULL;
return; return;
} }
@ -54,7 +54,7 @@ static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor)
/* Convert pattern (if specified) to UTF-16. */ /* Convert pattern (if specified) to UTF-16. */
if(pattern && pattern_len) { if(pattern && pattern_len) {
intl_convert_utf8_to_utf16(&spattern, &spattern_len, pattern, pattern_len, &INTL_DATA_ERROR_CODE(mfo)); 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", is_constructor); INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: error converting pattern to UTF-16");
} else { } else {
spattern_len = 0; spattern_len = 0;
spattern = NULL; spattern = NULL;
@ -66,7 +66,7 @@ static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor)
#ifdef MSG_FORMAT_QUOTE_APOS #ifdef MSG_FORMAT_QUOTE_APOS
if(msgformat_fix_quotes(&spattern, &spattern_len, &INTL_DATA_ERROR_CODE(mfo)) != SUCCESS) { 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", is_constructor); INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: error converting pattern to quote-friendly format");
} }
#endif #endif
@ -84,7 +84,7 @@ static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor)
efree(spattern); efree(spattern);
} }
INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: message formatter creation failed", is_constructor); INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: message formatter creation failed");
} }
/* }}} */ /* }}} */
@ -96,7 +96,7 @@ static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor)
PHP_FUNCTION( msgfmt_create ) PHP_FUNCTION( msgfmt_create )
{ {
object_init_ex( return_value, MessageFormatter_ce_ptr ); object_init_ex( return_value, MessageFormatter_ce_ptr );
msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
RETURN_NULL(); RETURN_NULL();
} }
@ -108,15 +108,17 @@ PHP_FUNCTION( msgfmt_create )
*/ */
PHP_METHOD( MessageFormatter, __construct ) 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(); return_value = getThis();
msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
zend_object_store_ctor_failed(Z_OBJ(orig_this)); if (!EG(exception)) {
ZEND_CTOR_MAKE_NULL(); zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
}
} }
zend_restore_error_handling(&error_handling);
} }
/* }}} */ /* }}} */

View file

@ -87,10 +87,10 @@ zend_object *MessageFormatter_object_clone(zval *object)
if (U_FAILURE(INTL_DATA_ERROR_CODE(mfo))) { if (U_FAILURE(INTL_DATA_ERROR_CODE(mfo))) {
intl_errors_set(INTL_DATA_ERROR_P(mfo), INTL_DATA_ERROR_CODE(mfo), intl_errors_set(INTL_DATA_ERROR_P(mfo), INTL_DATA_ERROR_CODE(mfo),
"Failed to clone MessageFormatter object", 0); "Failed to clone MessageFormatter object", 0);
zend_throw_exception_ex(IntlException_ce_ptr, 0, "Failed to clone MessageFormatter object"); zend_throw_exception_ex(NULL, 0, "Failed to clone MessageFormatter object");
} }
} else { } else {
zend_throw_exception_ex(IntlException_ce_ptr, 0, "Cannot clone unconstructed MessageFormatter"); zend_throw_exception_ex(NULL, 0, "Cannot clone unconstructed MessageFormatter");
} }
return new_obj; return new_obj;
} }

View file

@ -25,6 +25,7 @@
#include "php_intl.h" #include "php_intl.h"
#include "intl_data.h" #include "intl_data.h"
#include "intl_common.h"
#include "resourcebundle/resourcebundle.h" #include "resourcebundle/resourcebundle.h"
#include "resourcebundle/resourcebundle_iterator.h" #include "resourcebundle/resourcebundle_iterator.h"
@ -74,7 +75,7 @@ static zend_object *ResourceBundle_object_create( zend_class_entry *ce )
/* }}} */ /* }}} */
/* {{{ ResourceBundle_ctor */ /* {{{ ResourceBundle_ctor */
static void resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) static void resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS)
{ {
const char *bundlename; const char *bundlename;
size_t bundlename_len = 0; size_t bundlename_len = 0;
@ -90,8 +91,8 @@ static void resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_const
if( zend_parse_parameters( ZEND_NUM_ARGS(), "s!s!|b", if( zend_parse_parameters( ZEND_NUM_ARGS(), "s!s!|b",
&locale, &locale_len, &bundlename, &bundlename_len, &fallback ) == FAILURE ) &locale, &locale_len, &bundlename, &bundlename_len, &fallback ) == FAILURE )
{ {
intl_error_set_ex( NULL, U_ILLEGAL_ARGUMENT_ERROR, intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
"resourcebundle_ctor: unable to parse input parameters", 0, is_constructor ); "resourcebundle_ctor: unable to parse input parameters", 0 );
Z_OBJ_P(return_value) = NULL; Z_OBJ_P(return_value) = NULL;
return; return;
} }
@ -108,7 +109,7 @@ static void resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_const
rb->me = ures_openDirect(bundlename, locale, &INTL_DATA_ERROR_CODE(rb)); rb->me = ures_openDirect(bundlename, locale, &INTL_DATA_ERROR_CODE(rb));
} }
INTL_CTOR_CHECK_STATUS(rb, "resourcebundle_ctor: Cannot load libICU resource bundle", is_constructor); INTL_CTOR_CHECK_STATUS(rb, "resourcebundle_ctor: Cannot load libICU resource bundle");
if (!fallback && (INTL_DATA_ERROR_CODE(rb) == U_USING_FALLBACK_WARNING || if (!fallback && (INTL_DATA_ERROR_CODE(rb) == U_USING_FALLBACK_WARNING ||
INTL_DATA_ERROR_CODE(rb) == U_USING_DEFAULT_WARNING)) { INTL_DATA_ERROR_CODE(rb) == U_USING_DEFAULT_WARNING)) {
@ -119,7 +120,7 @@ static void resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_const
bundlename ? bundlename : "(default data)", locale, bundlename ? bundlename : "(default data)", locale,
ures_getLocaleByType( ures_getLocaleByType(
rb->me, ULOC_ACTUAL_LOCALE, &INTL_DATA_ERROR_CODE(rb))); rb->me, ULOC_ACTUAL_LOCALE, &INTL_DATA_ERROR_CODE(rb)));
intl_errors_set_custom_msg_ex(INTL_DATA_ERROR_P(rb), pbuf, 1, is_constructor); intl_errors_set_custom_msg(INTL_DATA_ERROR_P(rb), pbuf, 1);
efree(pbuf); efree(pbuf);
Z_OBJ_P(return_value) = NULL; Z_OBJ_P(return_value) = NULL;
} }
@ -139,15 +140,17 @@ ZEND_END_ARG_INFO()
*/ */
PHP_METHOD( ResourceBundle, __construct ) 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(); return_value = getThis();
resourcebundle_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); resourcebundle_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
zend_object_store_ctor_failed(Z_OBJ(orig_this)); if (!EG(exception)) {
ZEND_CTOR_MAKE_NULL(); zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
}
} }
zend_restore_error_handling(&error_handling);
} }
/* }}} */ /* }}} */
@ -157,7 +160,7 @@ proto ResourceBundle resourcebundle_create( string $locale [, string $bundlename
PHP_FUNCTION( resourcebundle_create ) PHP_FUNCTION( resourcebundle_create )
{ {
object_init_ex( return_value, ResourceBundle_ce_ptr ); object_init_ex( return_value, ResourceBundle_ce_ptr );
resourcebundle_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); resourcebundle_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
RETURN_NULL(); RETURN_NULL();
} }

View file

@ -30,15 +30,19 @@ PHP_METHOD(Spoofchecker, __construct)
{ {
int checks; int checks;
SPOOFCHECKER_METHOD_INIT_VARS; 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) { if (zend_parse_parameters_none() == FAILURE) {
zend_restore_error_handling(&error_handling);
return; return;
} }
SPOOFCHECKER_METHOD_FETCH_OBJECT_NO_CHECK; SPOOFCHECKER_METHOD_FETCH_OBJECT_NO_CHECK;
co->uspoof = uspoof_open(SPOOFCHECKER_ERROR_CODE_P(co)); co->uspoof = uspoof_open(SPOOFCHECKER_ERROR_CODE_P(co));
INTL_CTOR_CHECK_STATUS(co, "spoofchecker: unable to open ICU Spoof Checker", 1); INTL_CTOR_CHECK_STATUS(co, "spoofchecker: unable to open ICU Spoof Checker");
/* Single-script enforcement is on by default. This fails for languages /* Single-script enforcement is on by default. This fails for languages
like Japanese that legally use multiple scripts within a single word, like Japanese that legally use multiple scripts within a single word,
@ -46,6 +50,7 @@ PHP_METHOD(Spoofchecker, __construct)
*/ */
checks = uspoof_getChecks(co->uspoof, SPOOFCHECKER_ERROR_CODE_P(co)); checks = uspoof_getChecks(co->uspoof, SPOOFCHECKER_ERROR_CODE_P(co));
uspoof_setChecks(co->uspoof, checks & ~USPOOF_SINGLE_SCRIPT, SPOOFCHECKER_ERROR_CODE_P(co)); uspoof_setChecks(co->uspoof, checks & ~USPOOF_SINGLE_SCRIPT, SPOOFCHECKER_ERROR_CODE_P(co));
zend_restore_error_handling(&error_handling);
} }
/* }}} */ /* }}} */

View file

@ -7,32 +7,44 @@ IntlRuleBasedBreakIterator::__construct(): arg errors
<?php <?php
ini_set("intl.error_level", E_WARNING); ini_set("intl.error_level", E_WARNING);
//missing ; at the end: function print_exception($e) {
var_dump(new IntlRuleBasedBreakIterator('[\p{Letter}\uFFFD]+;[:number:]+')); echo "\nException: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n";
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));
//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-- --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 Exception: 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 Exception: 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 Exception: IntlRuleBasedBreakIterator::__construct() expects at most 2 parameters, 3 given in %s on line %d
NULL
Warning: IntlRuleBasedBreakIterator::__construct() expects at most 2 parameters, 3 given in %s on line %d Exception: IntlRuleBasedBreakIterator::__construct() expects parameter 2 to be boolean, array given in %s on line %d
Warning: IntlRuleBasedBreakIterator::__construct(): rbbi_create_instance: bad arguments in %s on line %d Exception: IntlRuleBasedBreakIterator::__construct(): rbbi_create_instance: unable to create instance from compiled rules in %s on line %d
NULL
Warning: IntlRuleBasedBreakIterator::__construct() expects parameter 2 to be boolean, array given in %s on line %d
Warning: IntlRuleBasedBreakIterator::__construct(): rbbi_create_instance: bad arguments in %s on line %d
NULL
Warning: IntlRuleBasedBreakIterator::__construct(): rbbi_create_instance: unable to create instance from compiled rules in %s on line %d
NULL

View file

@ -11,14 +11,14 @@ var_dump(
datefmt_create('', IntlDateFormatter::NONE, IntlDateFormatter::NONE, "\xFF", datefmt_create('', IntlDateFormatter::NONE, IntlDateFormatter::NONE, "\xFF",
IntlDateFormatter::GREGORIAN, 'a')); IntlDateFormatter::GREGORIAN, 'a'));
try { try {
new IntlDateFormatter('', IntlDateFormatter::NONE, IntlDateFormatter::NONE, "Europe/Lisbon", var_dump(
IntlDateFormatter::GREGORIAN, "\x80"); new IntlDateFormatter('', IntlDateFormatter::NONE, IntlDateFormatter::NONE, "Europe/Lisbon",
} IntlDateFormatter::GREGORIAN, "\x80"));
catch(IntlException $ie) { } catch (IntlException $e) {
echo $ie->getMessage().PHP_EOL; echo PHP_EOL."Exception: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . PHP_EOL;
} }
--EXPECTF-- --EXPECTF--
Warning: datefmt_create(): datefmt_create: Time zone identifier given is not a valid UTF-8 string in %s on line %d Warning: datefmt_create(): datefmt_create: Time zone identifier given is not a valid UTF-8 string in %s on line %d
NULL NULL
datefmt_create: error converting pattern to UTF-16
Exception: IntlDateFormatter::__construct(): datefmt_create: error converting pattern to UTF-16 in %sbug62017.php on line %d

View file

@ -12,5 +12,8 @@ ini_set('intl.error_level', E_WARNING);
$x = new IntlDateFormatter('en', 1, 1); $x = new IntlDateFormatter('en', 1, 1);
var_dump($x->__construct('en', 1, 1)); var_dump($x->__construct('en', 1, 1));
--EXPECTF-- --EXPECTF--
Warning: IntlDateFormatter::__construct(): datefmt_create: cannot call constructor twice in %s on line %d Fatal error: Uncaught exception 'IntlException' with message 'IntlDateFormatter::__construct(): datefmt_create: cannot call constructor twice' in %sbug62081.php:4
NULL Stack trace:
#0 %sbug62081.php(4): IntlDateFormatter->__construct('en', 1, 1)
#1 {main}
thrown in %sbug62081.php on line 4

View file

@ -10,23 +10,32 @@ ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "pt_PT"); ini_set("intl.default_locale", "pt_PT");
ini_set("date.timezone", 'Atlantic/Azores'); ini_set("date.timezone", 'Atlantic/Azores');
var_dump(new IntlDateFormatter(NULL, 0, 0, 'bad timezone')); function print_exception($e) {
echo "\nException: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n";
var_dump(new IntlDateFormatter(NULL, 0, 0, NULL, 3)); }
var_dump(new IntlDateFormatter(NULL, 0, 0, NULL, new stdclass));
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== ==DONE==
--EXPECTF-- --EXPECTF--
Warning: IntlDateFormatter::__construct(): datefmt_create: no such time zone: 'bad timezone' in %s on line %d Exception: IntlDateFormatter::__construct(): datefmt_create: no such time zone: 'bad timezone' in %s on line %d
NULL
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 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
NULL
Warning: IntlDateFormatter::__construct(): datefmt_create: Invalid calendar argument; should be an integer or an IntlCalendar instance in %s on line %d Exception: IntlDateFormatter::__construct(): datefmt_create: Invalid calendar argument; should be an integer or an IntlCalendar instance in %s on line %d
NULL
==DONE== ==DONE==

View file

@ -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(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" 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 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
==DONE== 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

View file

@ -11,24 +11,26 @@ function err($fmt) {
} }
} }
function print_exception($e) {
echo "\nException: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n";
}
function crt($t, $l, $s) { function crt($t, $l, $s) {
try { switch(true) {
$fmt = null; case $t == "O":
switch(true) { try {
case $t == "O": return new NumberFormatter($l, $s);
$fmt = new NumberFormatter($l, $s); } catch (IntlException $e) {
break; print_exception($e);
case $t == "C": return null;
$fmt = NumberFormatter::create($l, $s); }
break; break;
case $t == "P": case $t == "C":
$fmt = numfmt_create($l, $s); return NumberFormatter::create($l, $s);
break; break;
} case $t == "P":
err($fmt); return numfmt_create($l, $s);
} break;
catch(IntlException $ie) {
echo "IE: ".$ie->getMessage().PHP_EOL;
} }
} }
@ -42,11 +44,11 @@ $args = array(
try { try {
$fmt = new NumberFormatter(); $fmt = new NumberFormatter();
} catch (IntlException $e) {
print_exception($e);
$fmt = null;
} }
catch(IntlException $ie) { err($fmt);
echo $ie->getMessage().PHP_EOL;
}
$fmt = numfmt_create(); $fmt = numfmt_create();
err($fmt); err($fmt);
$fmt = NumberFormatter::create(); $fmt = NumberFormatter::create();
@ -54,13 +56,16 @@ err($fmt);
foreach($args as $arg) { foreach($args as $arg) {
$fmt = crt("O", $arg[0], $arg[1]); $fmt = crt("O", $arg[0], $arg[1]);
err($fmt);
$fmt = crt("C", $arg[0], $arg[1]); $fmt = crt("C", $arg[0], $arg[1]);
err($fmt);
$fmt = crt("P", $arg[0], $arg[1]); $fmt = crt("P", $arg[0], $arg[1]);
err($fmt);
} }
?> ?>
--EXPECTF-- --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' '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 Warning: numfmt_create() expects at least 2 parameters, 0 given in %s on line %d
@ -68,21 +73,27 @@ 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 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' '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' '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' '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 Warning: NumberFormatter::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: 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 Warning: numfmt_create() expects parameter 1 to be string, array given in %s on line %d
IE: numfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR '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 Exception: Constructor failed in %sformatter_fail.php on line %d
IE: numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR 'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR'
IE: numfmt_create: number formatter creation failed: U_MEMORY_ALLOCATION_ERROR 'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR'
IE: numfmt_create: number formatter creation failed: U_MEMORY_ALLOCATION_ERROR 'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR'
IE: numfmt_create: number formatter creation failed: U_MEMORY_ALLOCATION_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'

View file

@ -50,14 +50,7 @@ function ut_main()
$str_res .= "\nLocale is: $locale\n"; $str_res .= "\nLocale is: $locale\n";
foreach( $styles as $style => $pattern ) foreach( $styles as $style => $pattern )
{ {
try { $fmt = ut_nfmt_create( $locale, $style, $pattern );
$fmt = ut_nfmt_create( $locale, $style, $pattern );
}
catch (IntlException $ie) {
//$str_res .= "IE:".$ie->getMessage()."\n";
$str_res .= "Bad formatter!\n";
continue;
}
if(!$fmt) { if(!$fmt) {
$str_res .= "Bad formatter!\n"; $str_res .= "Bad formatter!\n";

View file

@ -8,23 +8,23 @@ if (!extension_loaded('intl'))
<?php <?php
ini_set("intl.error_level", E_WARNING); 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));
var_dump(intlgregcal_create_instance(1,2,3,4,5,6,7,8)); var_dump(intlgregcal_create_instance(1,2,3,4,5,6,7,8));
var_dump(intlgregcal_create_instance(1,2,3,4)); var_dump(intlgregcal_create_instance(1,2,3,4));
try { try {
new IntlGregorianCalendar(1,2,NULL,4); var_dump(new IntlGregorianCalendar(1,2,NULL,4));
} } catch (IntlException $e) {
catch (IntlException $ie) { print_exception($e);
echo "IE: ".$ie->getMessage().PHP_EOL;
} }
try { try {
new IntlGregorianCalendar(1,2,3,4,NULL,array()); var_dump(new IntlGregorianCalendar(1,2,3,4,NULL,array()));
} catch (IntlException $e) {
print_exception($e);
} }
catch (IntlException $ie) {
echo "IE: ".$ie->getMessage().PHP_EOL;
}
--EXPECTF-- --EXPECTF--
Warning: intlgregcal_create_instance(): intlgregcal_create_instance: too many arguments in %s on line %d Warning: intlgregcal_create_instance(): intlgregcal_create_instance: too many arguments in %s on line %d
@ -36,6 +36,6 @@ NULL
Warning: intlgregcal_create_instance(): intlgregcal_create_instance: no variant with 4 arguments (excluding trailing NULLs) in %s on line %d Warning: intlgregcal_create_instance(): intlgregcal_create_instance: no variant with 4 arguments (excluding trailing NULLs) in %s on line %d
NULL NULL
IE: IntlGregorianCalendar::__construct(): intlgregcal_create_instance: no variant with 4 arguments (excluding trailing NULLs) Exception: IntlGregorianCalendar::__construct(): intlgregcal_create_instance: no variant with 4 arguments (excluding trailing NULLs) in %s on line %d
Warning: IntlGregorianCalendar::__construct() expects parameter 6 to be integer, array given in %s on line %d
IE: IntlGregorianCalendar::__construct(): intlgregcal_create_instance: bad arguments Exception: IntlGregorianCalendar::__construct() expects parameter 6 to be integer, array given in %s on line %d

View file

@ -12,25 +12,26 @@ function err($fmt) {
} }
} }
function crt($t, $l, $s) { function print_exception($e) {
echo "\nException: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n";
}
try { function crt($t, $l, $s) {
$fmt = null; switch(true) {
switch(true) { case $t == "O":
case $t == "O": try {
$fmt = new MessageFormatter($l, $s); return new MessageFormatter($l, $s);
break; } catch (IntlException $e) {
case $t == "C": print_exception($e);
$fmt = MessageFormatter::create($l, $s); return null;
break; }
case $t == "P": break;
$fmt = msgfmt_create($l, $s); case $t == "C":
break; return MessageFormatter::create($l, $s);
} break;
err($fmt); case $t == "P":
} return msgfmt_create($l, $s);
catch (IntlException $ie) { break;
echo "IE: ".$ie->getMessage().PHP_EOL;
} }
} }
@ -45,34 +46,40 @@ $args = array(
try { try {
$fmt = new MessageFormatter(); $fmt = new MessageFormatter();
} catch (IntlException $e) {
print_exception($e);
$fmt = null;
} }
catch(IntlException $ie) { err($fmt);
echo "IE: ".$ie->getMessage().PHP_EOL;
}
$fmt = msgfmt_create(); $fmt = msgfmt_create();
err($fmt); err($fmt);
$fmt = MessageFormatter::create(); $fmt = MessageFormatter::create();
err($fmt); err($fmt);
try { try {
$fmt = new MessageFormatter('en'); $fmt = new MessageFormatter('en');
} catch (IntlException $e) {
print_exception($e);
$fmt = null;
} }
catch(IntlException $ie) { err($fmt);
echo "IE: ".$ie->getMessage().PHP_EOL;
}
$fmt = msgfmt_create('en'); $fmt = msgfmt_create('en');
err($fmt); err($fmt);
$fmt = MessageFormatter::create('en'); $fmt = MessageFormatter::create('en');
err($fmt); err($fmt);
foreach($args as $arg) { foreach($args as $arg) {
crt("O", $arg[0], $arg[1]); $fmt = crt("O", $arg[0], $arg[1]);
crt("C", $arg[0], $arg[1]); err($fmt);
crt("P", $arg[0], $arg[1]); $fmt = crt("C", $arg[0], $arg[1]);
err($fmt);
$fmt = crt("P", $arg[0], $arg[1]);
err($fmt);
} }
?> ?>
--EXPECTF-- --EXPECTF--
IE: msgfmt_create: unable to parse input parameters 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 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' 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
@ -80,21 +87,26 @@ 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 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' 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
IE: msgfmt_create: unable to parse input parameters 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 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' 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
Warning: MessageFormatter::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' 'msgfmt_create: unable to parse input parameters: 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'
'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' '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: Constructor failed in %smsgfmt_fail2.php on line %d
'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
Exception: MessageFormatter::__construct() expects parameter 1 to be string, array given in %s on line %d
'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' '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 Warning: MessageFormatter::create() expects parameter 1 to be string, array given in %s on line %d
@ -102,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 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' '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' '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' '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' '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'

View file

@ -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) { function crt($t, $l, $s) {
switch(true) { switch(true) {
case $t == "O": case $t == "O":
return new MessageFormatter($l, $s); try {
return new MessageFormatter($l, $s);
} catch (IntlException $e) {
print_exception($e);
return null;
}
break; break;
case $t == "C": case $t == "C":
return MessageFormatter::create($l, $s); return MessageFormatter::create($l, $s);
@ -35,13 +44,23 @@ $args = array(
array("en_US", "\xD0"), array("en_US", "\xD0"),
); );
$fmt = new MessageFormatter(); try {
$fmt = new MessageFormatter();
} catch (IntlException $e) {
print_exception($e);
$fmt = null;
}
err($fmt); err($fmt);
$fmt = msgfmt_create(); $fmt = msgfmt_create();
err($fmt); err($fmt);
$fmt = MessageFormatter::create(); $fmt = MessageFormatter::create();
err($fmt); err($fmt);
$fmt = new MessageFormatter('en'); try {
$fmt = new MessageFormatter('en');
} catch (IntlException $e) {
print_exception($e);
$fmt = null;
}
err($fmt); err($fmt);
$fmt = msgfmt_create('en'); $fmt = msgfmt_create('en');
err($fmt); err($fmt);
@ -59,7 +78,7 @@ foreach($args as $arg) {
?> ?>
--EXPECTF-- --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' '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 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 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' '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' '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 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 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' 'msgfmt_create: unable to parse input parameters: 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'
'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' '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: Constructor failed in %smsgfmt_fail2.php on line %d
'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
Exception: MessageFormatter::__construct() expects parameter 1 to be string, array given in %s on line %d
'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' '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 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 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' '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' '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' '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' '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'

View file

@ -36,15 +36,9 @@ function ut_main()
foreach( $locales as $locale => $pattern ) foreach( $locales as $locale => $pattern )
{ {
$str_res .= "\nLocale is: $locale\n"; $str_res .= "\nLocale is: $locale\n";
try { $fmt = ut_msgfmt_create( $locale, $pattern );
$fmt = ut_msgfmt_create( $locale, $pattern ); if(!$fmt) {
if(!$fmt) { $str_res .= dump(intl_get_error_message())."\n";
$str_res .= dump(intl_get_error_message())."\n";
continue;
}
}
catch (\IntlException $ie) {
$str_res .= "IE: ".$ie->getMessage().PHP_EOL;
continue; continue;
} }
$str_res .= dump( ut_msgfmt_parse( $fmt, $results[$locale] ) ) . "\n"; $str_res .= dump( ut_msgfmt_parse( $fmt, $results[$locale] ) ) . "\n";
@ -109,7 +103,7 @@ array (
) )
Locale is: root Locale is: root
IE: msgfmt_create: message formatter creation failed 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
Locale is: fr Locale is: fr
array ( array (

View file

@ -14,7 +14,6 @@ function ut_main() {
$str_res .= debug( $r1 ); $str_res .= debug( $r1 );
$str_res .= print_r( $r1['teststring'], true)."\n"; $str_res .= print_r( $r1['teststring'], true)."\n";
// non-root one // non-root one
$r1 = ut_resourcebundle_create( 'es', BUNDLE ); $r1 = ut_resourcebundle_create( 'es', BUNDLE );
$str_res .= debug( $r1 ); $str_res .= debug( $r1 );
@ -25,22 +24,14 @@ function ut_main() {
$str_res .= debug( $r1 ); $str_res .= debug( $r1 );
$str_res .= print_r( $r1['testsring'], true); $str_res .= print_r( $r1['testsring'], true);
try { // fall out
// fall out $r2 = ut_resourcebundle_create( 'en_US', BUNDLE, false );
$r2 = ut_resourcebundle_create( 'en_US', BUNDLE, false ); $str_res .= debug( $r2 );
}
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; return $str_res;
} }
@ -65,5 +56,7 @@ ResourceBundle Object
) )
-127: U_USING_DEFAULT_WARNING -127: U_USING_DEFAULT_WARNING
ie: resourcebundle_ctor: Cannot load libICU resource bundle NULL
ie: resourcebundle_ctor: Cannot load libICU resource bundle 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

View file

@ -132,7 +132,15 @@ function ut_coll_set_default( $coll )
function ut_nfmt_create( $locale, $style, $pattern = null ) 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 ) 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 ) 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 ) function ut_resourcebundle_count($bundle )
{ {

View file

@ -169,7 +169,7 @@ PHP_FUNCTION( transliterator_create_from_rules )
str_rules, str_rules_len, TRANSLITERATOR_ERROR_CODE_P( to ) ); str_rules, str_rules_len, TRANSLITERATOR_ERROR_CODE_P( to ) );
/* (I'm not a big fan of non-obvious flow control macros ). /* (I'm not a big fan of non-obvious flow control macros ).
* This one checks the error value, destroys object and returns false */ * This one checks the error value, destroys object and returns false */
INTL_CTOR_CHECK_STATUS( to, "String conversion of rules to UTF-16 failed", 0 ); INTL_CTOR_CHECK_STATUS( to, "String conversion of rules to UTF-16 failed" );
/* Open ICU Transliterator. */ /* Open ICU Transliterator. */
utrans = utrans_openU( id, ( sizeof( id ) - 1 ) / ( sizeof( *id ) ), (UTransDirection ) direction, 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 ) ); transliterator_object_construct( object, utrans, TRANSLITERATOR_ERROR_CODE_P( to ) );
/* no need to close the transliterator manually on construction error */ /* no need to close the transliterator manually on construction error */
INTL_CTOR_CHECK_STATUS( to, "transliterator_create_from_rules: internal constructor call failed", 0 ); INTL_CTOR_CHECK_STATUS( to, "transliterator_create_from_rules: internal constructor call failed" );
} }
/* }}} */ /* }}} */
@ -228,10 +228,10 @@ PHP_FUNCTION( transliterator_create_inverse )
utrans = utrans_openInverse( to_orig->utrans, TRANSLITERATOR_ERROR_CODE_P( to ) ); utrans = utrans_openInverse( to_orig->utrans, TRANSLITERATOR_ERROR_CODE_P( to ) );
INTL_CTOR_CHECK_STATUS( to, "transliterator_create_inverse: could not create " INTL_CTOR_CHECK_STATUS( to, "transliterator_create_inverse: could not create "
"inverse ICU transliterator", 0 ); "inverse ICU transliterator" );
transliterator_object_construct( object, utrans, TRANSLITERATOR_ERROR_CODE_P( to ) ); transliterator_object_construct( object, utrans, TRANSLITERATOR_ERROR_CODE_P( to ) );
/* no need to close the transliterator manually on construction error */ /* no need to close the transliterator manually on construction error */
INTL_CTOR_CHECK_STATUS( to, "transliterator_create: internal constructor call failed", 0 ); INTL_CTOR_CHECK_STATUS( to, "transliterator_create: internal constructor call failed" );
} }
/* }}} */ /* }}} */

View file

@ -209,15 +209,11 @@ static PHP_METHOD(PDO, dbh_constructor)
char alt_dsn[512]; char alt_dsn[512];
int call_factory = 1; int call_factory = 1;
zend_error_handling zeh; zend_error_handling zeh;
int rv;
zend_replace_error_handling(EH_THROW, pdo_exception_ce, &zeh TSRMLS_CC); zend_replace_error_handling(EH_THROW, pdo_exception_ce, &zeh);
rv = zend_parse_parameters(ZEND_NUM_ARGS(), "s|s!s!a!", &data_source, &data_source_len, if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "s|s!s!a!", &data_source, &data_source_len,
&username, &usernamelen, &password, &passwordlen, &options); &username, &usernamelen, &password, &passwordlen, &options)) {
zend_restore_error_handling(&zeh TSRMLS_CC); zend_restore_error_handling(&zeh);
if (FAILURE == rv) {
ZEND_CTOR_MAKE_NULL();
return; return;
} }
@ -230,8 +226,8 @@ static PHP_METHOD(PDO, dbh_constructor)
snprintf(alt_dsn, sizeof(alt_dsn), "pdo.dsn.%s", data_source); snprintf(alt_dsn, sizeof(alt_dsn), "pdo.dsn.%s", data_source);
if (FAILURE == cfg_get_string(alt_dsn, &ini_dsn)) { 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_throw_exception_ex(php_pdo_get_exception(), 0, "invalid data source name");
ZEND_CTOR_MAKE_NULL();
return; return;
} }
@ -239,8 +235,8 @@ static PHP_METHOD(PDO, dbh_constructor)
colon = strchr(data_source, ':'); colon = strchr(data_source, ':');
if (!colon) { 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_throw_exception_ex(php_pdo_get_exception(), 0, "invalid data source name (via INI: %s)", alt_dsn);
ZEND_CTOR_MAKE_NULL();
return; return;
} }
} }
@ -249,14 +245,14 @@ static PHP_METHOD(PDO, dbh_constructor)
/* the specified URI holds connection details */ /* the specified URI holds connection details */
data_source = dsn_from_uri(data_source + sizeof("uri:")-1, alt_dsn, sizeof(alt_dsn)); data_source = dsn_from_uri(data_source + sizeof("uri:")-1, alt_dsn, sizeof(alt_dsn));
if (!data_source) { if (!data_source) {
zend_restore_error_handling(&zeh);
zend_throw_exception_ex(php_pdo_get_exception(), 0, "invalid data source URI"); zend_throw_exception_ex(php_pdo_get_exception(), 0, "invalid data source URI");
ZEND_CTOR_MAKE_NULL();
return; return;
} }
colon = strchr(data_source, ':'); colon = strchr(data_source, ':');
if (!colon) { if (!colon) {
zend_restore_error_handling(&zeh);
zend_throw_exception_ex(php_pdo_get_exception(), 0, "invalid data source name (via URI)"); zend_throw_exception_ex(php_pdo_get_exception(), 0, "invalid data source name (via URI)");
ZEND_CTOR_MAKE_NULL();
return; return;
} }
} }
@ -266,8 +262,8 @@ static PHP_METHOD(PDO, dbh_constructor)
if (!driver) { if (!driver) {
/* NB: don't want to include the data_source in the error message as /* NB: don't want to include the data_source in the error message as
* it might contain a password */ * it might contain a password */
zend_restore_error_handling(&zeh);
zend_throw_exception_ex(php_pdo_get_exception(), 0, "could not find driver"); zend_throw_exception_ex(php_pdo_get_exception(), 0, "could not find driver");
ZEND_CTOR_MAKE_NULL();
return; return;
} }
@ -402,12 +398,16 @@ options:
} ZEND_HASH_FOREACH_END(); } ZEND_HASH_FOREACH_END();
} }
zend_restore_error_handling(&zeh);
return; return;
} }
/* the connection failed; things will tidy up in free_storage */ /* the connection failed; things will tidy up in free_storage */
/* XXX raise exception */ /* XXX raise exception */
ZEND_CTOR_MAKE_NULL(); zend_restore_error_handling(&zeh);
if (!EG(exception)) {
zend_throw_exception(pdo_exception_ce, "Constructor failed", 0);
}
} }
/* }}} */ /* }}} */
@ -465,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.called_scope = Z_OBJCE_P(object);
fcc.object = Z_OBJ_P(object); fcc.object = Z_OBJ_P(object);
if (zend_call_function(&fci, &fcc) == FAILURE) { 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)) {
zval_ptr_dtor(&retval); zval_ptr_dtor(&retval);
} }

View file

@ -113,8 +113,7 @@ ZEND_END_ARG_INFO()
RETURN_FALSE; \ RETURN_FALSE; \
} \ } \
//The class is called PDORow in userland, it is called PDOStatement in the manual. static PHP_FUNCTION(dbrow_constructor) /* {{{ */
static PHP_FUNCTION(dbstmt_constructor) /* {{{ */
{ {
zend_throw_exception_ex(php_pdo_get_exception(), 0, "You may not create a PDORow manually"); zend_throw_exception_ex(php_pdo_get_exception(), 0, "You may not create a PDORow manually");
} }
@ -2641,8 +2640,7 @@ static union _zend_function *row_get_ctor(zend_object *object)
ctor.type = ZEND_INTERNAL_FUNCTION; ctor.type = ZEND_INTERNAL_FUNCTION;
ctor.function_name = zend_string_init("__construct", sizeof("__construct") - 1, 0); ctor.function_name = zend_string_init("__construct", sizeof("__construct") - 1, 0);
ctor.scope = pdo_row_ce; ctor.scope = pdo_row_ce;
//The class is called PDORow in userland, it is called PDOStatement in the manual. ctor.handler = ZEND_FN(dbrow_constructor);
ctor.handler = ZEND_FN(dbstmt_constructor);
ctor.fn_flags = ZEND_ACC_PUBLIC; ctor.fn_flags = ZEND_ACC_PUBLIC;
return (union _zend_function*)&ctor; return (union _zend_function*)&ctor;

View file

@ -7,29 +7,22 @@ Testing PDORow and PDOStatement instances with Reflection
$instance = new reflectionclass('pdostatement'); $instance = new reflectionclass('pdostatement');
$x = $instance->newInstance(); $x = $instance->newInstance();
var_dump($x);
if ($x instanceof pdostatement) { $instance = new reflectionclass('pdorow');
echo "Ok".PHP_EOL; $x = $instance->newInstance();
} var_dump($x);
else {
echo "Failed to create instance of pdostatment";
}
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;
}
}
?> ?>
--EXPECTF-- --EXPECTF--
Ok object(PDOStatement)#%d (1) {
Ok [%u|b%"queryString"]=>
NULL
}
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

View file

@ -5,22 +5,12 @@ Trying instantiate a PDORow object manually
--FILE-- --FILE--
<?php <?php
try { new PDORow;
$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-- --EXPECTF--
Ok 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

View file

@ -28,8 +28,11 @@ MySQLPDOTest::skip();
try { try {
if (NULL !== ($db = @new PDO())) try {
printf("[001] Too few parameters\n"); if (NULL !== ($db = @new PDO()))
printf("[001] Too few parameters\n");
} catch (Exception $ex) {
}
print tryandcatch(2, '$db = new PDO(chr(0));'); print tryandcatch(2, '$db = new PDO(chr(0));');
print tryandcatch(3, '$db = new PDO("a" . chr(0) . "b");'); print tryandcatch(3, '$db = new PDO("a" . chr(0) . "b");');

View file

@ -67,8 +67,11 @@ MySQLPDOTest::skip();
PDO::MYSQL_ATTR_INIT_COMMAND => '', PDO::MYSQL_ATTR_INIT_COMMAND => '',
); );
if (NULL !== ($db = @new PDO($dsn, $user, $pass, 'wrong type'))) try {
printf("[001] Expecting NULL got %s/%s\n", gettype($db), $db); 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()))) if (!is_object($db = new PDO($dsn, $user, $pass, array())))
printf("[002] Expecting object got %s/%s¸\n", gettype($db), $db); printf("[002] Expecting object got %s/%s¸\n", gettype($db), $db);

View file

@ -68,9 +68,6 @@ MySQLPDOTest::skip();
print "done!"; print "done!";
?> ?>
--EXPECTF-- --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 [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 [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! done!

View file

@ -1149,7 +1149,7 @@ PHP_METHOD(Phar, __construct)
rv = zend_parse_parameters(ZEND_NUM_ARGS(), "s|ls!", &fname, &fname_len, &flags, &alias, &alias_len); rv = zend_parse_parameters(ZEND_NUM_ARGS(), "s|ls!", &fname, &fname_len, &flags, &alias, &alias_len);
zend_restore_error_handling(&zeh TSRMLS_CC); zend_restore_error_handling(&zeh TSRMLS_CC);
if (rv == FAILURE) { if (rv == FAILURE) {
//Exception was thrown already /* Exception was thrown already */
return; return;
} }
} }

View file

@ -7,16 +7,37 @@ phar.readonly=0
--FILE-- --FILE--
<?php <?php
ini_set('phar.readonly', 1); 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::mungServer('hi');
Phar::createDefaultStub(array()); Phar::createDefaultStub(array());
Phar::loadPhar(array()); Phar::loadPhar(array());
Phar::canCompress('hi'); Phar::canCompress('hi');
$a = new Phar(array()); try {
$a = new Phar(dirname(__FILE__) . '/files/frontcontroller10.phar'); $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->convertToExecutable(array());
$a->convertToData(array()); $a->convertToData(array());
$b = new PharData(dirname(__FILE__) . '/whatever.tar'); try {
$c = new PharData(dirname(__FILE__) . '/whatever.zip'); $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()); $b->delete(array());
try { try {
$a->delete('oops'); $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::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 Warning: Phar::convertToExecutable() expects parameter 1 to be integer, array given in %sbadparameters.php on line %d

View file

@ -14,6 +14,8 @@ try {
?> ?>
--EXPECTF-- --EXPECTF--
Fatal error: Uncaught exception 'PharException' with message 'Phar::__construct() expects at least 1 parameter, 0 given' in %sbug60261.php:3
Warning: Phar::__construct() expects at least 1 parameter, 0 given in %s on line %d Stack trace:
SplFileInfo::getLinkTarget(): Empty filename #0 %sbug60261.php(3): Phar->__construct()
#1 {main}
thrown in %sbug60261.php on line 3

View file

@ -47,8 +47,8 @@ echo $e->getMessage() . "\n";
--EXPECTF-- --EXPECTF--
Cannot open phar file 'phar://%spharfileinfo_construct.phar/oops': internal corruption of phar "%spharfileinfo_construct.phar" (truncated entry) 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 Fatal error: Uncaught exception 'PharException' with message 'PharFileInfo::__construct() expects parameter 1 to be string, array given' in %spharfileinfo_construct.php:13
Cannot access phar file entry '/oops/I/do/not/exist' in archive '%spharfileinfo_construct.phar' Stack trace:
Cannot call constructor twice #0 %spharfileinfo_construct.php(13): PharFileInfo->__construct(Array)
'%spharfileinfo_construct.php' is not a valid phar archive URL (must have at least phar://filename.phar) #1 {main}
===DONE=== thrown in %spharfileinfo_construct.php on line 13

View file

@ -1612,7 +1612,7 @@ ZEND_METHOD(reflection_function, __construct)
} }
efree(lcname); efree(lcname);
} else { } else {
//Exception has been thrown. /* Exception has been thrown. */
return; return;
} }
} }