Browse Source

Merge branch 'InternalClassClean'

* InternalClassClean:
  Fixed test
  Patch improvement:
  Fixed indentation. Fixed comment style. Fixed commented out code.
  Reverted change to function name and added note of why it is different from the class it is actually changing.
  Made UConverter throw an exception if the constructor fails.
  Fixed PDO constructor to not return null.
  Fixed fileinfo behaviour.
  Made Phar throw exception on bad constructor.
  Converted intl extension to use IntlException in constructors.
  Fixed SplFixedArray and tests.
  Fixed ReflectionExtension and ReflectionProperty.
  Fixed ReflectionFunction, ReflectionMethod and ReflectionParameter.
  Fixed PDORow behaviour and message.
pull/1177/merge
Dmitry Stogov 11 years ago
parent
commit
4796e0242b
  1. 1
      NEWS
  2. 9
      Zend/zend_API.c
  3. 6
      Zend/zend_API.h
  4. 7
      Zend/zend_vm_def.h
  5. 38
      Zend/zend_vm_execute.h
  6. 2
      ext/com_dotnet/com_com.c
  7. 3
      ext/com_dotnet/com_dotnet.c
  8. 10
      ext/date/php_date.c
  9. 49
      ext/fileinfo/fileinfo.c
  10. 7
      ext/fileinfo/tests/bug61173.phpt
  11. 8
      ext/fileinfo/tests/finfo_open_error.phpt
  12. 11
      ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp
  13. 13
      ext/intl/calendar/gregoriancalendar_methods.cpp
  14. 10
      ext/intl/collator/collator_create.c
  15. 11
      ext/intl/converter/converter.c
  16. 11
      ext/intl/dateformat/dateformat_create.cpp
  17. 10
      ext/intl/formatter/formatter_main.c
  18. 2
      ext/intl/intl_common.h
  19. 2
      ext/intl/intl_error.c
  20. 10
      ext/intl/msgformat/msgformat.c
  21. 11
      ext/intl/resourcebundle/resourcebundle_class.c
  22. 5
      ext/intl/spoofchecker/spoofchecker_create.c
  23. 56
      ext/intl/tests/breakiter___construct_error.phpt
  24. 14
      ext/intl/tests/bug62017.phpt
  25. 7
      ext/intl/tests/bug62081.phpt
  26. 35
      ext/intl/tests/dateformat___construct_bad_tz_cal.phpt
  27. 7
      ext/intl/tests/dateformat_calendars.phpt
  28. 7
      ext/intl/tests/dateformat_calendars_variant2.phpt
  29. 28
      ext/intl/tests/formatter_fail.phpt
  30. 26
      ext/intl/tests/gregoriancalendar___construct_error.phpt
  31. 43
      ext/intl/tests/msgfmt_fail.phpt
  32. 43
      ext/intl/tests/msgfmt_fail2.phpt
  33. 20
      ext/intl/tests/ut_common.inc
  34. 26
      ext/pdo/pdo_dbh.c
  35. 6
      ext/pdo/pdo_stmt.c
  36. 7
      ext/pdo/tests/pdo_036.phpt
  37. 6
      ext/pdo/tests/pdorow.phpt
  38. 7
      ext/pdo_mysql/tests/pdo_mysql___construct.phpt
  39. 7
      ext/pdo_mysql/tests/pdo_mysql___construct_options.phpt
  40. 3
      ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt
  41. 21
      ext/phar/phar_object.c
  42. 31
      ext/phar/tests/badparameters.phpt
  43. 8
      ext/phar/tests/bug60261.phpt
  44. 10
      ext/phar/tests/pharfileinfo_construct.phpt
  45. 80
      ext/reflection/php_reflection.c
  46. 30
      ext/reflection/tests/ReflectionExtension_constructor_error.phpt
  47. 39
      ext/reflection/tests/ReflectionFunction_construct.001.phpt
  48. 31
      ext/reflection/tests/ReflectionMethod_006.phpt
  49. 39
      ext/reflection/tests/ReflectionMethod_constructor_error2.phpt
  50. 21
      ext/reflection/tests/ReflectionParameter_invalidMethodInConstructor.phpt
  51. 50
      ext/reflection/tests/ReflectionProperty_error.phpt
  52. 9
      ext/spl/spl_fixedarray.c
  53. 9
      ext/spl/tests/SplFixedArray__construct_param_array.phpt
  54. 9
      ext/spl/tests/SplFixedArray__construct_param_string.phpt
  55. 13
      ext/spl/tests/SplFixedArray_construct_param_SplFixedArray.phpt
  56. 10
      ext/spl/tests/fixedarray_005.phpt
  57. 10
      ext/spl/tests/fixedarray_009.phpt
  58. 40
      ext/spl/tests/fixedarray_015.phpt

1
NEWS

@ -59,6 +59,7 @@
. Implemented the RFC `Scalar Type Decalarations v0.5`. (Anthony)
. Implemented the RFC `Group Use Declarations`. (Marcio)
. Implemented the RFC `Continue Output Buffering`. (Mike)
. Implemented the RFC `Constructor behaviour of internal classes`. (Dan, Dmitry)
- Curl:
. Fixed bug #68937 (Segfault in curl_multi_exec). (Laruence)

9
Zend/zend_API.c

@ -4128,15 +4128,6 @@ ZEND_API zend_string *zend_resolve_method_name(zend_class_entry *ce, zend_functi
}
/* }}} */
ZEND_API void zend_ctor_make_null(zend_execute_data *execute_data) /* {{{ */
{
if (EX(return_value)) {
Z_OBJ_P(EX(return_value)) = NULL;
ZVAL_NULL(EX(return_value));
}
}
/* }}} */
ZEND_API const char *zend_get_object_type(const zend_class_entry *ce) /* {{{ */
{
if(ce->ce_flags & ZEND_ACC_TRAIT) {

6
Zend/zend_API.h

@ -538,8 +538,6 @@ ZEND_API int zend_set_local_var_str(const char *name, size_t len, zval *value, i
ZEND_API zend_string *zend_find_alias_name(zend_class_entry *ce, zend_string *name);
ZEND_API zend_string *zend_resolve_method_name(zend_class_entry *ce, zend_function *f);
ZEND_API void zend_ctor_make_null(zend_execute_data *execute_data);
ZEND_API const char *zend_get_object_type(const zend_class_entry *ce);
#define add_method(arg, key, method) add_assoc_function((arg), (key), (method))
@ -651,10 +649,6 @@ END_EXTERN_C()
} \
} while (0)
/* May be used in internal constructors to make them return NULL */
#define ZEND_CTOR_MAKE_NULL() \
zend_ctor_make_null(execute_data)
#define RETURN_ZVAL_FAST(z) { RETVAL_ZVAL_FAST(z); return; }
#define HASH_OF(p) (Z_TYPE_P(p)==IS_ARRAY ? Z_ARRVAL_P(p) : ((Z_TYPE_P(p)==IS_OBJECT ? Z_OBJ_HT_P(p)->get_properties((p)) : NULL)))

7
Zend/zend_vm_def.h

@ -2962,10 +2962,6 @@ ZEND_VM_HANDLER(113, ZEND_INIT_STATIC_METHOD_CALL, CONST|VAR, CONST|TMPVAR|UNUSE
EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call));
if (OP2_TYPE == IS_UNUSED) {
EX(call)->return_value = NULL;
}
CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
@ -4720,9 +4716,6 @@ ZEND_VM_HANDLER(68, ZEND_NEW, CONST|VAR, ANY)
if (EXPECTED(RETURN_VALUE_USED(opline))) {
ZVAL_COPY(EX_VAR(opline->result.var), &object_zval);
EX(call)->return_value = EX_VAR(opline->result.var);
} else {
EX(call)->return_value = NULL;
}
CHECK_EXCEPTION();

38
Zend/zend_vm_execute.h

@ -3112,9 +3112,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_NEW_SPEC_CONST_HANDLER(ZEND_OP
if (EXPECTED(RETURN_VALUE_USED(opline))) {
ZVAL_COPY(EX_VAR(opline->result.var), &object_zval);
EX(call)->return_value = EX_VAR(opline->result.var);
} else {
EX(call)->return_value = NULL;
}
CHECK_EXCEPTION();
@ -5104,10 +5101,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_C
EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call));
if (IS_CONST == IS_UNUSED) {
EX(call)->return_value = NULL;
}
CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
@ -7032,10 +7025,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_C
EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call));
if (IS_UNUSED == IS_UNUSED) {
EX(call)->return_value = NULL;
}
CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
@ -8520,10 +8509,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_C
EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call));
if (IS_CV == IS_UNUSED) {
EX(call)->return_value = NULL;
}
CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
@ -10071,10 +10056,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_C
EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call));
if ((IS_TMP_VAR|IS_VAR) == IS_UNUSED) {
EX(call)->return_value = NULL;
}
CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
@ -13851,9 +13832,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_NEW_SPEC_VAR_HANDLER(ZEND_OPCO
if (EXPECTED(RETURN_VALUE_USED(opline))) {
ZVAL_COPY(EX_VAR(opline->result.var), &object_zval);
EX(call)->return_value = EX_VAR(opline->result.var);
} else {
EX(call)->return_value = NULL;
}
CHECK_EXCEPTION();
@ -15938,10 +15916,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_V
EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call));
if (IS_CONST == IS_UNUSED) {
EX(call)->return_value = NULL;
}
CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
@ -17515,10 +17489,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_V
EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call));
if (IS_UNUSED == IS_UNUSED) {
EX(call)->return_value = NULL;
}
CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
@ -19134,10 +19104,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_V
EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call));
if (IS_CV == IS_UNUSED) {
EX(call)->return_value = NULL;
}
CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
@ -20695,10 +20661,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_V
EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call));
if ((IS_TMP_VAR|IS_VAR) == IS_UNUSED) {
EX(call)->return_value = NULL;
}
CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}

2
ext/com_dotnet/com_com.c

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

3
ext/com_dotnet/com_dotnet.c

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

10
ext/date/php_date.c

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

49
ext/fileinfo/fileinfo.c

@ -282,15 +282,6 @@ PHP_MINFO_FUNCTION(fileinfo)
}
/* }}} */
#define FILEINFO_DESTROY_OBJECT(object) \
do { \
if (object) { \
zend_object_store_ctor_failed(Z_OBJ_P(object)); \
Z_OBJ_P(object) = NULL; \
ZEND_CTOR_MAKE_NULL(); \
} \
} while (0)
/* {{{ proto resource finfo_open([int options [, string arg]])
Create a new fileinfo resource. */
PHP_FUNCTION(finfo_open)
@ -301,9 +292,18 @@ PHP_FUNCTION(finfo_open)
php_fileinfo *finfo;
FILEINFO_DECLARE_INIT_OBJECT(object)
char resolved_path[MAXPATHLEN];
zend_error_handling zeh;
if (object) {
zend_replace_error_handling(EH_THROW, NULL, &zeh);
}
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|lp", &options, &file, &file_len) == FAILURE) {
FILEINFO_DESTROY_OBJECT(object);
if (object) {
zend_restore_error_handling(&zeh);
if (!EG(exception)) {
zend_throw_exception(NULL, "Constructor failed", 0);
}
}
RETURN_FALSE;
}
@ -322,11 +322,21 @@ PHP_FUNCTION(finfo_open)
} else if (file && *file) { /* user specified file, perform open_basedir checks */
if (php_check_open_basedir(file)) {
FILEINFO_DESTROY_OBJECT(object);
if (object) {
zend_restore_error_handling(&zeh);
if (!EG(exception)) {
zend_throw_exception(NULL, "Constructor failed", 0);
}
}
RETURN_FALSE;
}
if (!expand_filepath_with_mode(file, resolved_path, NULL, 0, CWD_EXPAND)) {
FILEINFO_DESTROY_OBJECT(object);
if (object) {
zend_restore_error_handling(&zeh);
if (!EG(exception)) {
zend_throw_exception(NULL, "Constructor failed", 0);
}
}
RETURN_FALSE;
}
file = resolved_path;
@ -340,7 +350,12 @@ PHP_FUNCTION(finfo_open)
if (finfo->magic == NULL) {
efree(finfo);
php_error_docref(NULL, E_WARNING, "Invalid mode '%pd'.", options);
FILEINFO_DESTROY_OBJECT(object);
if (object) {
zend_restore_error_handling(&zeh);
if (!EG(exception)) {
zend_throw_exception(NULL, "Constructor failed", 0);
}
}
RETURN_FALSE;
}
@ -348,11 +363,17 @@ PHP_FUNCTION(finfo_open)
php_error_docref(NULL, E_WARNING, "Failed to load magic database at '%s'.", file);
magic_close(finfo->magic);
efree(finfo);
FILEINFO_DESTROY_OBJECT(object);
if (object) {
zend_restore_error_handling(&zeh);
if (!EG(exception)) {
zend_throw_exception(NULL, "Constructor failed", 0);
}
}
RETURN_FALSE;
}
if (object) {
zend_restore_error_handling(&zeh);
FILEINFO_REGISTER_OBJECT(object, finfo);
} else {
RETURN_RES(zend_register_resource(finfo, le_fileinfo));

7
ext/fileinfo/tests/bug61173.phpt

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

8
ext/fileinfo/tests/finfo_open_error.phpt

@ -46,6 +46,8 @@ resource(6) of type (file_info)
Warning: finfo_open() expects parameter 1 to be integer, string given in %sfinfo_open_error.php on line 16
bool(false)
Warning: finfo::finfo() expects parameter 1 to be integer, string given in %sfinfo_open_error.php on line 18
NULL
===DONE===
Fatal error: Uncaught exception 'Exception' with message 'finfo::finfo() expects parameter 1 to be integer, string given' in %sfinfo_open_error.php:18
Stack trace:
#0 %sfinfo_open_error.php(18): finfo->finfo('foobar')
#1 {main}
thrown in %sfinfo_open_error.php on line 18

11
ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp

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

13
ext/intl/calendar/gregoriancalendar_methods.cpp

@ -25,11 +25,13 @@
#include <unicode/gregocal.h>
extern "C" {
#include "../php_intl.h"
#include "../intl_common.h"
#define USE_TIMEZONE_POINTER 1
#include "../timezone/timezone_class.h"
#define USE_CALENDAR_POINTER 1
#include "calendar_class.h"
#include <ext/date/php_date.h>
#include "zend_exceptions.h"
}
static inline GregorianCalendar *fetch_greg(Calendar_object *co) {
@ -189,17 +191,18 @@ U_CFUNC PHP_FUNCTION(intlgregcal_create_instance)
U_CFUNC PHP_METHOD(IntlGregorianCalendar, __construct)
{
zval orig_this = *getThis();
intl_error_reset(NULL);
zend_error_handling error_handling;
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
return_value = getThis();
//changes this to IS_NULL (without first destroying) if there's an error
_php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU);
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
zend_object_store_ctor_failed(Z_OBJ(orig_this));
ZEND_CTOR_MAKE_NULL();
if (!EG(exception)) {
zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
}
}
zend_restore_error_handling(&error_handling);
}
U_CFUNC PHP_FUNCTION(intlgregcal_set_gregorian_change)

10
ext/intl/collator/collator_create.c

@ -72,15 +72,17 @@ PHP_FUNCTION( collator_create )
*/
PHP_METHOD( Collator, __construct )
{
zval orig_this = *getThis();
zend_error_handling error_handling;
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
return_value = getThis();
collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
zend_object_store_ctor_failed(Z_OBJ(orig_this));
ZEND_CTOR_MAKE_NULL();
if (!EG(exception)) {
zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
}
}
zend_restore_error_handling(&error_handling);
}
/* }}} */

11
ext/intl/converter/converter.c

@ -22,6 +22,7 @@
#include <unicode/ustring.h>
#include "../intl_error.h"
#include "../intl_common.h"
typedef struct _php_converter_object {
UConverter *src, *dest;
@ -556,11 +557,17 @@ static PHP_METHOD(UConverter, __construct) {
size_t src_len = sizeof("utf-8") - 1;
char *dest = src;
size_t dest_len = src_len;
zend_error_handling zeh;
int rv;
intl_error_reset(NULL);
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s!",
&dest, &dest_len, &src, &src_len) == FAILURE) {
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &zeh);
rv = zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s!",
&dest, &dest_len, &src, &src_len);
zend_restore_error_handling(&zeh);
if (rv == FAILURE) {
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"UConverter::__construct(): bad arguments", 0);
return;

11
ext/intl/dateformat/dateformat_create.cpp

@ -34,6 +34,7 @@ extern "C" {
}
#include "dateformat_helpers.h"
#include "zend_exceptions.h"
/* {{{ */
static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
@ -187,16 +188,18 @@ U_CFUNC PHP_FUNCTION( datefmt_create )
*/
U_CFUNC PHP_METHOD( IntlDateFormatter, __construct )
{
zval orig_this = *getThis();
zend_error_handling error_handling;
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
/* return_value param is being changed, therefore we will always return
* NULL here */
return_value = getThis();
datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
zend_object_store_ctor_failed(Z_OBJ(orig_this));
ZEND_CTOR_MAKE_NULL();
if (!EG(exception)) {
zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
}
}
zend_restore_error_handling(&error_handling);
}
/* }}} */

10
ext/intl/formatter/formatter_main.c

@ -90,15 +90,17 @@ PHP_FUNCTION( numfmt_create )
*/
PHP_METHOD( NumberFormatter, __construct )
{
zval orig_this = *getThis();
zend_error_handling error_handling;
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
return_value = getThis();
numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
zend_object_store_ctor_failed(Z_OBJ(orig_this));
ZEND_CTOR_MAKE_NULL();
if (!EG(exception)) {
zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
}
}
zend_restore_error_handling(&error_handling);
}
/* }}} */

2
ext/intl/intl_common.h

@ -41,4 +41,6 @@
#define INTL_Z_STRVAL_P(str) (UChar*) Z_STRVAL_P(str)
#define INTL_Z_STRLEN_P(str) UCHARS( Z_STRLEN_P(str) )
extern zend_class_entry *IntlException_ce_ptr;
#endif /* INTL_COMMON_H */

2
ext/intl/intl_error.c

@ -29,7 +29,7 @@
ZEND_EXTERN_MODULE_GLOBALS( intl )
static zend_class_entry *IntlException_ce_ptr;
zend_class_entry *IntlException_ce_ptr;
/* {{{ intl_error* intl_g_error_get()
* Return global error structure.

10
ext/intl/msgformat/msgformat.c

@ -108,15 +108,17 @@ PHP_FUNCTION( msgfmt_create )
*/
PHP_METHOD( MessageFormatter, __construct )
{
zval orig_this = *getThis();
zend_error_handling error_handling;
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
return_value = getThis();
msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
zend_object_store_ctor_failed(Z_OBJ(orig_this));
ZEND_CTOR_MAKE_NULL();
if (!EG(exception)) {
zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
}
}
zend_restore_error_handling(&error_handling);
}
/* }}} */

11
ext/intl/resourcebundle/resourcebundle_class.c

@ -25,6 +25,7 @@
#include "php_intl.h"
#include "intl_data.h"
#include "intl_common.h"
#include "resourcebundle/resourcebundle.h"
#include "resourcebundle/resourcebundle_iterator.h"
@ -139,15 +140,17 @@ ZEND_END_ARG_INFO()
*/
PHP_METHOD( ResourceBundle, __construct )
{
zval orig_this = *getThis();
zend_error_handling error_handling;
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
return_value = getThis();
resourcebundle_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
zend_object_store_ctor_failed(Z_OBJ(orig_this));
ZEND_CTOR_MAKE_NULL();
if (!EG(exception)) {
zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
}
}
zend_restore_error_handling(&error_handling);
}
/* }}} */

5
ext/intl/spoofchecker/spoofchecker_create.c

@ -30,8 +30,12 @@ PHP_METHOD(Spoofchecker, __construct)
{
int checks;
SPOOFCHECKER_METHOD_INIT_VARS;
zend_error_handling error_handling;
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
if (zend_parse_parameters_none() == FAILURE) {
zend_restore_error_handling(&error_handling);
return;
}
@ -46,6 +50,7 @@ PHP_METHOD(Spoofchecker, __construct)
*/
checks = uspoof_getChecks(co->uspoof, SPOOFCHECKER_ERROR_CODE_P(co));
uspoof_setChecks(co->uspoof, checks & ~USPOOF_SINGLE_SCRIPT, SPOOFCHECKER_ERROR_CODE_P(co));
zend_restore_error_handling(&error_handling);
}
/* }}} */

56
ext/intl/tests/breakiter___construct_error.phpt

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

14
ext/intl/tests/bug62017.phpt

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

7
ext/intl/tests/bug62081.phpt

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

35
ext/intl/tests/dateformat___construct_bad_tz_cal.phpt

@ -10,23 +10,32 @@ ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "pt_PT");
ini_set("date.timezone", 'Atlantic/Azores');
var_dump(new IntlDateFormatter(NULL, 0, 0, 'bad timezone'));
var_dump(new IntlDateFormatter(NULL, 0, 0, NULL, 3));
var_dump(new IntlDateFormatter(NULL, 0, 0, NULL, new stdclass));
function print_exception($e) {
echo "\nException: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n";
}
try {
var_dump(new IntlDateFormatter(NULL, 0, 0, 'bad timezone'));
} catch (IntlException $e) {
print_exception($e);
}
try {
var_dump(new IntlDateFormatter(NULL, 0, 0, NULL, 3));
} catch (IntlException $e) {
print_exception($e);
}
try {
var_dump(new IntlDateFormatter(NULL, 0, 0, NULL, new stdclass));
} catch (IntlException $e) {
print_exception($e);
}
?>
==DONE==
--EXPECTF--
Warning: IntlDateFormatter::__construct(): datefmt_create: no such time zone: 'bad timezone' in %s on line %d
NULL
Exception: IntlDateFormatter::__construct(): datefmt_create: no such time zone: 'bad timezone' in %s on line %d
Warning: IntlDateFormatter::__construct(): datefmt_create: invalid value for calendar type; it must be one of IntlDateFormatter::TRADITIONAL (locale's default calendar) or IntlDateFormatter::GREGORIAN. Alternatively, it can be an IntlCalendar object in %s on line %d
NULL
Exception: IntlDateFormatter::__construct(): datefmt_create: invalid value for calendar type; it must be one of IntlDateFormatter::TRADITIONAL (locale's default calendar) or IntlDateFormatter::GREGORIAN. Alternatively, it can be an IntlCalendar object in %s on line %d
Warning: IntlDateFormatter::__construct(): datefmt_create: Invalid calendar argument; should be an integer or an IntlCalendar instance in %s on line %d
NULL
Exception: IntlDateFormatter::__construct(): datefmt_create: Invalid calendar argument; should be an integer or an IntlCalendar instance in %s on line %d
==DONE==

7
ext/intl/tests/dateformat_calendars.phpt

@ -41,5 +41,8 @@ string(44) "Sunday, January 1, 2012 5:12:00 AM GMT+05:12"
string(44) "Sunday, January 1, 2012 5:12:00 AM GMT+05:12"
string(42) "Sunday, Tevet 6, 5772 5:12:00 AM GMT+05:12"
Warning: IntlDateFormatter::__construct(): datefmt_create: invalid value for calendar type; it must be one of IntlDateFormatter::TRADITIONAL (locale's default calendar) or IntlDateFormatter::GREGORIAN. Alternatively, it can be an IntlCalendar object in %s on line %d
==DONE==
Fatal error: Uncaught exception 'IntlException' with message 'IntlDateFormatter::__construct(): datefmt_create: invalid value for calendar type; it must be one of IntlDateFormatter::TRADITIONAL (locale's default calendar) or IntlDateFormatter::GREGORIAN. Alternatively, it can be an IntlCalendar object' in %sdateformat_calendars.php:%d
Stack trace:
#0 %sdateformat_calendars.php(%d): IntlDateFormatter->__construct('en_US@calendar=...', 0, 0, 'GMT+05:12', -1)
#1 {main}
thrown in %sdateformat_calendars.php on line %d

7
ext/intl/tests/dateformat_calendars_variant2.phpt

@ -42,5 +42,8 @@ string(47) "Sunday, January 1, 2012 at 5:12:00 AM GMT+05:12"
string(47) "Sunday, January 1, 2012 at 5:12:00 AM GMT+05:12"
string(48) "Sunday, Tevet 6, 5772 AM at 5:12:00 AM GMT+05:12"
Warning: IntlDateFormatter::__construct(): datefmt_create: invalid value for calendar type; it must be one of IntlDateFormatter::TRADITIONAL (locale's default calendar) or IntlDateFormatter::GREGORIAN. Alternatively, it can be an IntlCalendar object in %sdateformat_calendars_variant2.php on line %d
==DONE==
Fatal error: Uncaught exception 'IntlException' with message 'IntlDateFormatter::__construct(): datefmt_create: invalid value for calendar type; it must be one of IntlDateFormatter::TRADITIONAL (locale's default calendar) or IntlDateFormatter::GREGORIAN. Alternatively, it can be an IntlCalendar object' in %sdateformat_calendars_variant2.php:27
Stack trace:
#0 %sdateformat_calendars_variant2.php(27): IntlDateFormatter->__construct('en_US@calendar=...', 0, 0, 'GMT+05:12', -1)
#1 {main}
thrown in %sdateformat_calendars_variant2.php on line 27

28
ext/intl/tests/formatter_fail.phpt

@ -11,10 +11,19 @@ function err($fmt) {
}
}
function print_exception($e) {
echo "\nException: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n";
}
function crt($t, $l, $s) {
switch(true) {
case $t == "O":
return new NumberFormatter($l, $s);
try {
return new NumberFormatter($l, $s);
} catch (IntlException $e) {
print_exception($e);
return null;
}
break;
case $t == "C":
return NumberFormatter::create($l, $s);
@ -33,7 +42,12 @@ $args = array(
array("en_US", NumberFormatter::PATTERN_RULEBASED),
);
$fmt = new NumberFormatter();
try {
$fmt = new NumberFormatter();
} catch (IntlException $e) {
print_exception($e);
$fmt = null;
}
err($fmt);
$fmt = numfmt_create();
err($fmt);
@ -51,7 +65,7 @@ foreach($args as $arg) {
?>
--EXPECTF--
Warning: NumberFormatter::__construct() expects at least 2 parameters, 0 given in %s on line %d
Exception: NumberFormatter::__construct() expects at least 2 parameters, 0 given in %s on line %d
'numfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
Warning: numfmt_create() expects at least 2 parameters, 0 given in %s on line %d
@ -59,11 +73,13 @@ Warning: numfmt_create() expects at least 2 parameters, 0 given in %s on line %d
Warning: NumberFormatter::create() expects at least 2 parameters, 0 given in %s on line %d
'numfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
Exception: Constructor failed in %sformatter_fail.php on line %d
'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR'
'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR'
'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR'
Warning: NumberFormatter::__construct() expects parameter 1 to be string, array given in %s on line %d
Exception: NumberFormatter::__construct() expects parameter 1 to be string, array given in %s on line %d
'numfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
Warning: NumberFormatter::create() expects parameter 1 to be string, array given in %s on line %d
@ -71,9 +87,13 @@ Warning: NumberFormatter::create() expects parameter 1 to be string, array given
Warning: numfmt_create() expects parameter 1 to be string, array given in %s on line %d
'numfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
Exception: Constructor failed in %sformatter_fail.php on line %d
'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR'
'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR'
'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR'
Exception: Constructor failed in %sformatter_fail.php on line %d
'numfmt_create: number formatter creation failed: U_MEMORY_ALLOCATION_ERROR'
'numfmt_create: number formatter creation failed: U_MEMORY_ALLOCATION_ERROR'
'numfmt_create: number formatter creation failed: U_MEMORY_ALLOCATION_ERROR'

26
ext/intl/tests/gregoriancalendar___construct_error.phpt

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

43
ext/intl/tests/msgfmt_fail.phpt

@ -12,10 +12,19 @@ function err($fmt) {
}
}
function print_exception($e) {
echo "\nException: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n";
}
function crt($t, $l, $s) {
switch(true) {
case $t == "O":
return new MessageFormatter($l, $s);
try {
return new MessageFormatter($l, $s);
} catch (IntlException $e) {
print_exception($e);
return null;
}
break;
case $t == "C":
return MessageFormatter::create($l, $s);
@ -35,13 +44,23 @@ $args = array(
array("en_US", "\xD0"),
);
$fmt = new MessageFormatter();
try {
$fmt = new MessageFormatter();
} catch (IntlException $e) {
print_exception($e);
$fmt = null;
}
err($fmt);
$fmt = msgfmt_create();
err($fmt);
$fmt = MessageFormatter::create();
err($fmt);
$fmt = new MessageFormatter('en');
err($fmt);
try {
$fmt = new MessageFormatter('en');
} catch (IntlException $e) {
print_exception($e);
$fmt = null;
}
err($fmt);
$fmt = msgfmt_create('en');
err($fmt);
@ -59,7 +78,7 @@ foreach($args as $arg) {
?>
--EXPECTF--
Warning: MessageFormatter::__construct() expects exactly 2 parameters, 0 given in %s on line %d
Exception: MessageFormatter::__construct() expects exactly 2 parameters, 0 given in %s on line %d
'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
Warning: msgfmt_create() expects exactly 2 parameters, 0 given in %s on line %d
@ -68,7 +87,7 @@ Warning: msgfmt_create() expects exactly 2 parameters, 0 given in %s on line %d
Warning: MessageFormatter::create() expects exactly 2 parameters, 0 given in %s on line %d
'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
Warning: MessageFormatter::__construct() expects exactly 2 parameters, 1 given in %s on line %d
Exception: MessageFormatter::__construct() expects exactly 2 parameters, 1 given in %s on line %d
'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
Warning: msgfmt_create() expects exactly 2 parameters, 1 given in %s on line %d
@ -76,14 +95,18 @@ Warning: msgfmt_create() expects exactly 2 parameters, 1 given in %s on line %d
Warning: MessageFormatter::create() expects exactly 2 parameters, 1 given in %s on line %d
'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
Exception: Constructor failed in %smsgfmt_fail2.php on line %d
'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
Exception: Constructor failed in %smsgfmt_fail2.php on line %d
'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
Warning: MessageFormatter::__construct() expects parameter 1 to be string, array given in %s on line %d
Exception: MessageFormatter::__construct() expects parameter 1 to be string, array given in %s on line %d
'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
Warning: MessageFormatter::create() expects parameter 1 to be string, array given in %s on line %d
@ -91,12 +114,18 @@ Warning: MessageFormatter::create() expects parameter 1 to be string, array give
Warning: msgfmt_create() expects parameter 1 to be string, array given in %s on line %d
'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
Exception: Constructor failed in %smsgfmt_fail2.php on line %d
'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
Exception: Constructor failed in %smsgfmt_fail2.php on line %d
'msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES'
'msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES'
'msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES'
Exception: Constructor failed in %smsgfmt_fail2.php on line %d
'msgfmt_create: error converting pattern to UTF-16: U_INVALID_CHAR_FOUND'
'msgfmt_create: error converting pattern to UTF-16: U_INVALID_CHAR_FOUND'
'msgfmt_create: error converting pattern to UTF-16: U_INVALID_CHAR_FOUND'

43
ext/intl/tests/msgfmt_fail2.phpt

@ -12,10 +12,19 @@ function err($fmt) {
}
}
function print_exception($e) {
echo "\nException: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n";
}
function crt($t, $l, $s) {
switch(true) {
case $t == "O":
return new MessageFormatter($l, $s);
try {
return new MessageFormatter($l, $s);
} catch (IntlException $e) {
print_exception($e);
return null;
}
break;
case $t == "C":
return MessageFormatter::create($l, $s);
@ -35,13 +44,23 @@ $args = array(
array("en_US", "\xD0"),
);
$fmt = new MessageFormatter();
try {
$fmt = new MessageFormatter();
} catch (IntlException $e) {
print_exception($e);
$fmt = null;
}
err($fmt);
$fmt = msgfmt_create();
err($fmt);
$fmt = MessageFormatter::create();
err($fmt);
$fmt = new MessageFormatter('en');
err($fmt);
try {
$fmt = new MessageFormatter('en');
} catch (IntlException $e) {
print_exception($e);
$fmt = null;
}
err($fmt);
$fmt = msgfmt_create('en');
err($fmt);
@ -59,7 +78,7 @@ foreach($args as $arg) {
?>
--EXPECTF--
Warning: MessageFormatter::__construct() expects exactly 2 parameters, 0 given in %s on line %d
Exception: MessageFormatter::__construct() expects exactly 2 parameters, 0 given in %s on line %d
'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
Warning: msgfmt_create() expects exactly 2 parameters, 0 given in %s on line %d
@ -68,7 +87,7 @@ Warning: msgfmt_create() expects exactly 2 parameters, 0 given in %s on line %d
Warning: MessageFormatter::create() expects exactly 2 parameters, 0 given in %s on line %d
'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
Warning: MessageFormatter::__construct() expects exactly 2 parameters, 1 given in %s on line %d
Exception: MessageFormatter::__construct() expects exactly 2 parameters, 1 given in %s on line %d
'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
Warning: msgfmt_create() expects exactly 2 parameters, 1 given in %s on line %d
@ -76,14 +95,18 @@ Warning: msgfmt_create() expects exactly 2 parameters, 1 given in %s on line %d
Warning: MessageFormatter::create() expects exactly 2 parameters, 1 given in %s on line %d
'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
Exception: Constructor failed in %smsgfmt_fail2.php on line %d
'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
Exception: Constructor failed in %smsgfmt_fail2.php on line %d
'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
Warning: MessageFormatter::__construct() expects parameter 1 to be string, array given in %s on line %d
Exception: MessageFormatter::__construct() expects parameter 1 to be string, array given in %s on line %d
'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
Warning: MessageFormatter::create() expects parameter 1 to be string, array given in %s on line %d
@ -91,12 +114,18 @@ Warning: MessageFormatter::create() expects parameter 1 to be string, array give
Warning: msgfmt_create() expects parameter 1 to be string, array given in %s on line %d
'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR'
Exception: Constructor failed in %smsgfmt_fail2.php on line %d
'msgfmt_create: message formatter creation failed: U_PATTERN_SYNTAX_ERROR'
'msgfmt_create: message formatter creation failed: U_PATTERN_SYNTAX_ERROR'
'msgfmt_create: message formatter creation failed: U_PATTERN_SYNTAX_ERROR'
Exception: Constructor failed in %smsgfmt_fail2.php on line %d
'msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES'
'msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES'
'msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES'
Exception: Constructor failed in %smsgfmt_fail2.php on line %d
'msgfmt_create: error converting pattern to UTF-16: U_INVALID_CHAR_FOUND'
'msgfmt_create: error converting pattern to UTF-16: U_INVALID_CHAR_FOUND'
'msgfmt_create: error converting pattern to UTF-16: U_INVALID_CHAR_FOUND'

20
ext/intl/tests/ut_common.inc

@ -132,7 +132,15 @@ function ut_coll_set_default( $coll )
function ut_nfmt_create( $locale, $style, $pattern = null )
{
return $GLOBALS['oo-mode'] ? new NumberFormatter( $locale, $style, $pattern ) : numfmt_create( $locale, $style, $pattern );
if ($GLOBALS['oo-mode']) {
try {
return new NumberFormatter( $locale, $style, $pattern );
} catch (Exception $e) {
return NULL;
}
} else {
return numfmt_create( $locale, $style, $pattern );
}
}
function ut_nfmt_format( $fmt, $number, $type = null )
{
@ -392,7 +400,15 @@ function ut_datefmt_localtime( $fmt , $value , &$parse_pos=0 )
function ut_resourcebundle_create( $locale, $bundle, $fallback=true )
{
return $GLOBALS['oo-mode'] ? new ResourceBundle($locale, $bundle, $fallback): resourcebundle_create($locale, $bundle, $fallback);
if ($GLOBALS['oo-mode']) {
try {
return new ResourceBundle($locale, $bundle, $fallback);
} catch (Exception $e) {
return NULL;
}
} else {
return resourcebundle_create($locale, $bundle, $fallback);
}
}
function ut_resourcebundle_count($bundle )
{

26
ext/pdo/pdo_dbh.c

@ -208,10 +208,12 @@ static PHP_METHOD(PDO, dbh_constructor)
zval *options = NULL;
char alt_dsn[512];
int call_factory = 1;
zend_error_handling zeh;
zend_replace_error_handling(EH_THROW, pdo_exception_ce, &zeh);
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "s|s!s!a!", &data_source, &data_source_len,
&username, &usernamelen, &password, &passwordlen, &options)) {
ZEND_CTOR_MAKE_NULL();
zend_restore_error_handling(&zeh);
return;
}
@ -224,8 +226,8 @@ static PHP_METHOD(PDO, dbh_constructor)
snprintf(alt_dsn, sizeof(alt_dsn), "pdo.dsn.%s", data_source);
if (FAILURE == cfg_get_string(alt_dsn, &ini_dsn)) {
zend_restore_error_handling(&zeh);
zend_throw_exception_ex(php_pdo_get_exception(), 0, "invalid data source name");
ZEND_CTOR_MAKE_NULL();
return;
}
@ -233,8 +235,8 @@ static PHP_METHOD(PDO, dbh_constructor)
colon = strchr(data_source, ':');
if (!colon) {
zend_restore_error_handling(&zeh);
zend_throw_exception_ex(php_pdo_get_exception(), 0, "invalid data source name (via INI: %s)", alt_dsn);
ZEND_CTOR_MAKE_NULL();
return;
}
}
@ -243,14 +245,14 @@ static PHP_METHOD(PDO, dbh_constructor)
/* the specified URI holds connection details */
data_source = dsn_from_uri(data_source + sizeof("uri:")-1, alt_dsn, sizeof(alt_dsn));
if (!data_source) {
zend_restore_error_handling(&zeh);
zend_throw_exception_ex(php_pdo_get_exception(), 0, "invalid data source URI");
ZEND_CTOR_MAKE_NULL();
return;
}
colon = strchr(data_source, ':');
if (!colon) {
zend_restore_error_handling(&zeh);
zend_throw_exception_ex(php_pdo_get_exception(), 0, "invalid data source name (via URI)");
ZEND_CTOR_MAKE_NULL();
return;
}
}
@ -260,8 +262,8 @@ static PHP_METHOD(PDO, dbh_constructor)
if (!driver) {
/* NB: don't want to include the data_source in the error message as
* it might contain a password */
zend_restore_error_handling(&zeh);
zend_throw_exception_ex(php_pdo_get_exception(), 0, "could not find driver");
ZEND_CTOR_MAKE_NULL();
return;
}
@ -396,12 +398,16 @@ options:
} ZEND_HASH_FOREACH_END();
}
zend_restore_error_handling(&zeh);
return;
}
/* the connection failed; things will tidy up in free_storage */
/* XXX raise exception */
ZEND_CTOR_MAKE_NULL();
zend_restore_error_handling(&zeh);
if (!EG(exception)) {
zend_throw_exception(pdo_exception_ce, "Constructor failed", 0);
}
}
/* }}} */
@ -459,11 +465,7 @@ static void pdo_stmt_construct(zend_execute_data *execute_data, pdo_stmt_t *stmt
fcc.called_scope = Z_OBJCE_P(object);
fcc.object = Z_OBJ_P(object);
if (zend_call_function(&fci, &fcc) == FAILURE) {
Z_OBJ_P(object) = NULL;
ZEND_CTOR_MAKE_NULL();
object = NULL; /* marks failure */
} else if (!Z_ISUNDEF(retval)) {
if (zend_call_function(&fci, &fcc) != FAILURE) {
zval_ptr_dtor(&retval);
}

6
ext/pdo/pdo_stmt.c

@ -113,9 +113,9 @@ ZEND_END_ARG_INFO()
RETURN_FALSE; \
} \
static PHP_FUNCTION(dbstmt_constructor) /* {{{ */
static PHP_FUNCTION(dbrow_constructor) /* {{{ */
{
php_error_docref(NULL, E_ERROR, "You should not create a PDOStatement manually");
zend_throw_exception_ex(php_pdo_get_exception(), 0, "You may not create a PDORow manually");
}
/* }}} */
@ -2640,7 +2640,7 @@ static union _zend_function *row_get_ctor(zend_object *object)
ctor.type = ZEND_INTERNAL_FUNCTION;
ctor.function_name = zend_string_init("__construct", sizeof("__construct") - 1, 0);
ctor.scope = pdo_row_ce;
ctor.handler = ZEND_FN(dbstmt_constructor);
ctor.handler = ZEND_FN(dbrow_constructor);
ctor.fn_flags = ZEND_ACC_PUBLIC;
return (union _zend_function*)&ctor;

7
ext/pdo/tests/pdo_036.phpt

@ -20,4 +20,9 @@ object(PDOStatement)#%d (1) {
NULL
}
Fatal error: PDORow::__construct(): You should not create a PDOStatement manually in %spdo_036.php on line %d
Fatal error: Uncaught exception 'PDOException' with message 'You may not create a PDORow manually' in %spdo_036.php:8
Stack trace:
#0 [internal function]: PDORow->__construct()
#1 %spdo_036.php(8): ReflectionClass->newInstance()
#2 {main}
thrown in %spdo_036.php on line 8

6
ext/pdo/tests/pdorow.phpt

@ -9,4 +9,8 @@ new PDORow;
?>
--EXPECTF--
Fatal error: PDORow::__construct(): You should not create a PDOStatement manually in %s on line %d
Fatal error: Uncaught exception 'PDOException' with message 'You may not create a PDORow manually' in %spdorow.php:3
Stack trace:
#0 %spdorow.php(3): PDORow->__construct()
#1 {main}
thrown in %spdorow.php on line 3

7
ext/pdo_mysql/tests/pdo_mysql___construct.phpt

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

7
ext/pdo_mysql/tests/pdo_mysql___construct_options.phpt

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

3
ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt

@ -68,9 +68,6 @@ MySQLPDOTest::skip();
print "done!";
?>
--EXPECTF--
Warning: PDO::__construct(%s
[002] URI=uri:file:%spdomuri.tst, DSN=mysql%sdbname=%s, File=%spdomuri.tst (%d bytes, 'mysql%sdbname=%s'), invalid data source URI
Warning: PDO::__construct(%s
[003] URI=uri:file:%spdomuri.tst, DSN=mysql%sdbname=%s, File=%spdomuri.tst (%d bytes, 'mysql%sdbname=letshopeinvalid%s'), chr(0) test, invalid data source URI
done!

21
ext/phar/phar_object.c

@ -1130,17 +1130,26 @@ PHP_METHOD(Phar, __construct)
phar_archive_object *phar_obj;
phar_archive_data *phar_data;
zval *zobj = getThis(), arg1, arg2;
zend_error_handling zeh;
int rv;
phar_obj = (phar_archive_object*)((char*)Z_OBJ_P(zobj) - Z_OBJ_P(zobj)->handlers->offset);
is_data = instanceof_function(Z_OBJCE_P(zobj), phar_ce_data);
if (is_data) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|ls!l", &fname, &fname_len, &flags, &alias, &alias_len, &format) == FAILURE) {
zend_replace_error_handling(EH_THROW, phar_ce_PharException, &zeh TSRMLS_CC);
rv = zend_parse_parameters(ZEND_NUM_ARGS(), "s|ls!l", &fname, &fname_len, &flags, &alias, &alias_len, &format);
zend_restore_error_handling(&zeh TSRMLS_CC);
if (rv == FAILURE) {
return;
}
} else {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|ls!", &fname, &fname_len, &flags, &alias, &alias_len) == FAILURE) {
zend_replace_error_handling(EH_THROW, phar_ce_PharException, &zeh TSRMLS_CC);
rv = zend_parse_parameters(ZEND_NUM_ARGS(), "s|ls!", &fname, &fname_len, &flags, &alias, &alias_len);
zend_restore_error_handling(&zeh TSRMLS_CC);
if (rv == FAILURE) {
/* Exception was thrown already */
return;
}
}
@ -4350,8 +4359,14 @@ PHP_METHOD(PharFileInfo, __construct)
phar_entry_info *entry_info;
phar_archive_data *phar_data;
zval *zobj = getThis(), arg1;
zend_error_handling zeh;
int rv;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &fname, &fname_len) == FAILURE) {
zend_replace_error_handling(EH_THROW, phar_ce_PharException, &zeh TSRMLS_CC);
rv = zend_parse_parameters(ZEND_NUM_ARGS(), "s", &fname, &fname_len);
zend_restore_error_handling(&zeh TSRMLS_CC);
if (rv == FAILURE) {
return;
}

31
ext/phar/tests/badparameters.phpt

@ -7,16 +7,37 @@ phar.readonly=0
--FILE--
<?php
ini_set('phar.readonly', 1);
function print_exception($e) {
echo "\nException: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n";
}
Phar::mungServer('hi');
Phar::createDefaultStub(array());
Phar::loadPhar(array());
Phar::canCompress('hi');
$a = new Phar(array());
$a = new Phar(dirname(__FILE__) . '/files/frontcontroller10.phar');
try {
$a = new Phar(array());
} catch (PharException $e) {
print_exception($e);
}
try {
$a = new Phar(dirname(__FILE__) . '/files/frontcontroller10.phar');
} catch (PharException $e) {
print_exception($e);
}
$a->convertToExecutable(array());
$a->convertToData(array());
$b = new PharData(dirname(__FILE__) . '/whatever.tar');
$c = new PharData(dirname(__FILE__) . '/whatever.zip');
try {
$b = new PharData(dirname(__FILE__) . '/whatever.tar');
} catch (PharException $e) {
print_exception($e);
}
try {
$c = new PharData(dirname(__FILE__) . '/whatever.zip');
} catch (PharException $e) {
print_exception($e);
}
$b->delete(array());
try {
$a->delete('oops');
@ -132,7 +153,7 @@ Warning: Phar::loadPhar() expects parameter 1 to be %string, array given in %sba
Warning: Phar::canCompress() expects parameter 1 to be integer, %string given in %sbadparameters.php on line %d
Warning: Phar::__construct() expects parameter 1 to be %string, array given in %sbadparameters.php on line %d
Exception: Phar::__construct() expects parameter 1 to be %string, array given in %sbadparameters.php on line %d
Warning: Phar::convertToExecutable() expects parameter 1 to be integer, array given in %sbadparameters.php on line %d

8
ext/phar/tests/bug60261.phpt

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

10
ext/phar/tests/pharfileinfo_construct.phpt

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

80
ext/reflection/php_reflection.c

@ -1577,6 +1577,8 @@ ZEND_METHOD(reflection_function, __construct)
zend_function *fptr;
char *name_str;
size_t name_len;
int rv;
zend_error_handling zeh;
object = getThis();
intern = Z_REFLECTION_P(object);
@ -1587,27 +1589,32 @@ ZEND_METHOD(reflection_function, __construct)
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "O", &closure, zend_ce_closure) == SUCCESS) {
fptr = (zend_function*)zend_get_closure_method_def(closure);
Z_ADDREF_P(closure);
} else if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name_str, &name_len) == SUCCESS) {
char *nsname;
lcname = zend_str_tolower_dup(name_str, name_len);
/* Ignore leading "\" */
nsname = lcname;
if (lcname[0] == '\\') {
nsname = &lcname[1];
name_len--;
}
if ((fptr = zend_hash_str_find_ptr(EG(function_table), nsname, name_len)) == NULL) {
} else {
zend_replace_error_handling(EH_THROW, reflection_exception_ptr, &zeh TSRMLS_CC);
rv = zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name_str, &name_len);
zend_restore_error_handling(&zeh TSRMLS_CC);
if (rv == SUCCESS) {
char *nsname;
lcname = zend_str_tolower_dup(name_str, name_len);
/* Ignore leading "\" */
nsname = lcname;
if (lcname[0] == '\\') {
nsname = &lcname[1];
name_len--;
}
if ((fptr = zend_hash_str_find_ptr(EG(function_table), nsname, name_len)) == NULL) {
efree(lcname);
zend_throw_exception_ex(reflection_exception_ptr, 0,
"Function %s() does not exist", name_str);
return;
}
efree(lcname);
zend_throw_exception_ex(reflection_exception_ptr, 0,
"Function %s() does not exist", name_str);
} else {
/* Exception has been thrown. */
return;
}
efree(lcname);
} else {
return;
}
ZVAL_STR_COPY(&name, fptr->common.function_name);
@ -2129,10 +2136,14 @@ ZEND_METHOD(reflection_parameter, __construct)
zend_class_entry *ce = NULL;
zend_bool is_closure = 0;
zend_bool is_invoke = 0;
zend_error_handling zeh;
zend_replace_error_handling(EH_THROW, reflection_exception_ptr, &zeh TSRMLS_CC);
if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &reference, &parameter) == FAILURE) {
zend_restore_error_handling(&zeh TSRMLS_CC);
return;
}
zend_restore_error_handling(&zeh TSRMLS_CC);
object = getThis();
intern = Z_REFLECTION_P(object);
@ -2713,7 +2724,13 @@ ZEND_METHOD(reflection_method, __construct)
zval ztmp;
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "zs", &classname, &name_str, &name_len) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name_str, &name_len) == FAILURE) {
zend_error_handling zeh;
int rv;
zend_replace_error_handling(EH_THROW, reflection_exception_ptr, &zeh TSRMLS_CC);
rv = zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name_str, &name_len);
zend_restore_error_handling(&zeh TSRMLS_CC);
if (rv == FAILURE) {
return;
}
if ((tmp = strstr(name_str, "::")) == NULL) {
@ -4786,7 +4803,14 @@ ZEND_METHOD(reflection_property, __construct)
zend_property_info *property_info = NULL;
property_reference *reference;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "zs", &classname, &name_str, &name_len) == FAILURE) {
int rv;
zend_error_handling zeh;
zend_replace_error_handling(EH_THROW, reflection_exception_ptr, &zeh TSRMLS_CC);
rv = zend_parse_parameters(ZEND_NUM_ARGS(), "zs", &classname, &name_str, &name_len);
zend_restore_error_handling(&zeh TSRMLS_CC);
if (rv == FAILURE) {
return;
}
@ -5181,9 +5205,15 @@ ZEND_METHOD(reflection_extension, __construct)
zend_module_entry *module;
char *name_str;
size_t name_len;
int rv;
zend_error_handling zeh;
ALLOCA_FLAG(use_heap)
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name_str, &name_len) == FAILURE) {
zend_replace_error_handling(EH_THROW, reflection_exception_ptr, &zeh TSRMLS_CC);
rv = zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name_str, &name_len);
zend_restore_error_handling(&zeh TSRMLS_CC);
if (rv == FAILURE) {
return;
}
@ -5550,8 +5580,14 @@ ZEND_METHOD(reflection_zend_extension, __construct)
zend_extension *extension;
char *name_str;
size_t name_len;
int rv;
zend_error_handling zeh;
zend_replace_error_handling(EH_THROW, reflection_exception_ptr, &zeh TSRMLS_CC);
rv = zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name_str, &name_len);
zend_restore_error_handling(&zeh TSRMLS_CC);
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name_str, &name_len) == FAILURE) {
if (rv == FAILURE) {
return;
}

30
ext/reflection/tests/ReflectionExtension_constructor_error.phpt

@ -5,12 +5,32 @@ Gerrit "Remi" te Sligte <remi@wolerized.com>
Leon Luijkx <leon@phpgg.nl>
--FILE--
<?php
$obj = new ReflectionExtension();
$test = $obj instanceof ReflectionExtension;
var_dump($test);
try {
$obj = new ReflectionExtension();
}
catch(ReflectionException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
try {
$obj = new ReflectionExtension('foo', 'bar');
}
catch(ReflectionException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
try {
$obj = new ReflectionExtension([]);
}
catch(ReflectionException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
?>
==DONE==
--EXPECTF--
Warning: ReflectionExtension::__construct() expects exactly %d parameter, %d given in %s.php on line %d
bool(true)
Ok - ReflectionExtension::__construct() expects exactly %d parameter, %d given
Ok - ReflectionExtension::__construct() expects exactly %d parameter, %d given
Ok - ReflectionExtension::__construct() expects parameter 1 to be string, array given
==DONE==

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

@ -6,18 +6,41 @@ Steve Seear <stevseea@php.net>
--FILE--
<?php
$a = new ReflectionFunction(array(1, 2, 3));
try {
$a = new ReflectionFunction(array(1, 2, 3));
echo "exception not thrown.".PHP_EOL;
}
catch(ReflectionException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
try {
$a = new ReflectionFunction('nonExistentFunction');
} catch (Exception $e) {
echo $e->getMessage();
echo $e->getMessage().PHP_EOL;
}
try {
$a = new ReflectionFunction();
}
catch(ReflectionException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
try {
$a = new ReflectionFunction(1, 2);
}
catch(ReflectionException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
try {
$a = new ReflectionFunction([]);
}
$a = new ReflectionFunction();
$a = new ReflectionFunction(1, 2);
catch(ReflectionException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
?>
--EXPECTF--
Warning: ReflectionFunction::__construct() expects parameter 1 to be string, array given in %s on line %d
Ok - ReflectionFunction::__construct() expects parameter 1 to be string, array given
Function nonExistentFunction() does not exist
Warning: ReflectionFunction::__construct() expects exactly 1 parameter, 0 given in %s on line %d
Warning: ReflectionFunction::__construct() expects exactly 1 parameter, 2 given in %s on line %d
Ok - ReflectionFunction::__construct() expects exactly 1 parameter, 0 given
Ok - ReflectionFunction::__construct() expects exactly 1 parameter, 2 given
Ok - ReflectionFunction::__construct() expects parameter 1 to be string, array given

31
ext/reflection/tests/ReflectionMethod_006.phpt

@ -6,8 +6,18 @@ Steve Seear <stevseea@php.net>
--FILE--
<?php
var_dump(new ReflectionMethod());
var_dump(new ReflectionMethod('a', 'b', 'c'));
try {
new ReflectionMethod();
}
catch(ReflectionException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
try {
new ReflectionMethod('a', 'b', 'c');
}
catch(ReflectionException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
class C {
public function f() {}
@ -35,21 +45,8 @@ var_dump($rm->getName(1));
?>
--EXPECTF--
Warning: ReflectionMethod::__construct() expects exactly 1 parameter, 0 given in %s on line %d
object(ReflectionMethod)#%d (2) {
["name"]=>
string(0) ""
["class"]=>
string(0) ""
}
Warning: ReflectionMethod::__construct() expects exactly 1 parameter, 3 given in %s on line %d
object(ReflectionMethod)#%d (2) {
["name"]=>
string(0) ""
["class"]=>
string(0) ""
}
Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 0 given
Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 3 given
Warning: ReflectionMethod::isFinal() expects exactly 0 parameters, 1 given in %s on line %d
NULL

39
ext/reflection/tests/ReflectionMethod_constructor_error2.phpt

@ -16,22 +16,47 @@ class TestClass
try {
echo "Too few arguments:\n";
$methodInfo = new ReflectionMethod();
} catch (Exception $e) {
print $e->__toString();
} catch (ReflectionException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
try {
echo "\nToo many arguments:\n";
$methodInfo = new ReflectionMethod("TestClass", "foo", true);
} catch (Exception $e) {
print $e->__toString();
} catch (ReflectionException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
try {
//invalid class
$methodInfo = new ReflectionMethod("InvalidClassName", "foo");
} catch (ReflectionException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
try {
//invalid 1st param
$methodInfo = new ReflectionMethod([], "foo");
} catch (ReflectionException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
try{
//invalid 2nd param
$methodInfo = new ReflectionMethod("TestClass", []);
} catch (ReflectionException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
?>
--EXPECTF--
Too few arguments:
Warning: ReflectionMethod::__construct() expects exactly 1 parameter, 0 given in %s on line 12
Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 0 given
Too many arguments:
Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 3 given
Ok - Class InvalidClassName does not exist
Ok - The parameter class is expected to be either a string or an object
Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 2 given
Warning: ReflectionMethod::__construct() expects exactly 1 parameter, 3 given in %s on line 18

21
ext/reflection/tests/ReflectionParameter_invalidMethodInConstructor.phpt

@ -6,7 +6,7 @@ ReflectionParameter::__construct(): Invalid method as constructor
// Invalid class name
try {
new ReflectionParameter (array ('A', 'b'), 0);
} catch (ReflectionException $e) { echo $e->getMessage ()."\n"; }
} catch (ReflectionException $e) { echo $e->getMessage()."\n"; }
// Invalid class method
try {
@ -18,14 +18,31 @@ try {
new ReflectionParameter (array (new C, 'b'), 0);
} catch (ReflectionException $e) { echo $e->getMessage ()."\n"; }
echo "Done.\n";
class C {
}
try {
new ReflectionParameter(array ('A', 'b'));
}
catch(ReflectionException $e) {
printf( "Ok - %s\n", $e->getMessage());
}
try {
new ReflectionParameter(0, 0);
}
catch(ReflectionException $e) {
printf( "Ok - %s\n", $e->getMessage());
}
echo "Done.\n";
?>
--EXPECTF--
Class A does not exist
Method C::b() does not exist
Method C::b() does not exist
Ok - ReflectionParameter::__construct() expects exactly 2 parameters, 1 given
Ok - The parameter class is expected to be either a string, an array(class, method) or a callable object
Done.

50
ext/reflection/tests/ReflectionProperty_error.phpt

@ -7,9 +7,27 @@ class C {
public static $p;
}
var_dump(new ReflectionProperty());
var_dump(new ReflectionProperty('C::p'));
var_dump(new ReflectionProperty('C', 'p', 'x'));
try {
new ReflectionProperty();
}
catch(ReflectionException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
try {
new ReflectionProperty('C::p');
}
catch(ReflectionException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
try {
new ReflectionProperty('C', 'p', 'x');
}
catch(ReflectionException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
$rp = new ReflectionProperty('C', 'p');
var_dump($rp->getName(1));
var_dump($rp->isPrivate(1));
@ -21,29 +39,9 @@ var_dump($rp->isDefault(1));
?>
--EXPECTF--
Warning: ReflectionProperty::__construct() expects exactly 2 parameters, 0 given in %s on line %d
object(ReflectionProperty)#%d (2) {
["name"]=>
string(0) ""
["class"]=>
string(0) ""
}
Warning: ReflectionProperty::__construct() expects exactly 2 parameters, 1 given in %s on line %d
object(ReflectionProperty)#%d (2) {
["name"]=>
string(0) ""
["class"]=>
string(0) ""
}
Warning: ReflectionProperty::__construct() expects exactly 2 parameters, 3 given in %s on line %d
object(ReflectionProperty)#%d (2) {
["name"]=>
string(0) ""
["class"]=>
string(0) ""
}
Ok - ReflectionProperty::__construct() expects exactly 2 parameters, 0 given
Ok - ReflectionProperty::__construct() expects exactly 2 parameters, 1 given
Ok - ReflectionProperty::__construct() expects exactly 2 parameters, 3 given
Warning: ReflectionProperty::getName() expects exactly 0 parameters, 1 given in %s on line %d
NULL

9
ext/spl/spl_fixedarray.c

@ -561,7 +561,14 @@ SPL_METHOD(SplFixedArray, __construct)
spl_fixedarray_object *intern;
zend_long size = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &size) == FAILURE) {
int rv;
zend_error_handling zeh;
zend_replace_error_handling(EH_THROW, spl_ce_InvalidArgumentException, &zeh TSRMLS_CC);
rv = zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &size);
zend_restore_error_handling(&zeh TSRMLS_CC);
if (rv == FAILURE) {
return;
}

9
ext/spl/tests/SplFixedArray__construct_param_array.phpt

@ -5,8 +5,13 @@ PHPNW Test Fest 2009 - Jordan Hatch
--FILE--
<?php
$array = new SplFixedArray( array("string", 1) );
try {
$array = new SplFixedArray( array("string", 1) );
}
catch(InvalidArgumentException $iae) {
echo "Ok - ".$iae->getMessage().PHP_EOL;
}
?>
--EXPECTF--
Warning: SplFixedArray::__construct() expects parameter 1 to be integer, array given in %s on line %d
Ok - SplFixedArray::__construct() expects parameter 1 to be integer, array given

9
ext/spl/tests/SplFixedArray__construct_param_string.phpt

@ -4,9 +4,14 @@ SplFixedArray::__construct() with string passed as parameter.
PHPNW Test Fest 2009 - Jordan Hatch
--FILE--
<?php
try {
$array = new SplFixedArray( "string" );
}
catch(InvalidArgumentException $iae) {
echo "Ok - ".$iae->getMessage().PHP_EOL;
}
$array = new SplFixedArray( "string" );
?>
--EXPECTF--
Warning: SplFixedArray::__construct() expects parameter 1 to be integer, %unicode_string_optional% given in %s on line %d
Ok - SplFixedArray::__construct() expects parameter 1 to be integer, %unicode_string_optional% given

13
ext/spl/tests/SplFixedArray_construct_param_SplFixedArray.phpt

@ -4,10 +4,13 @@ Create an SplFixedArray using an SplFixedArray object.
Philip Norton philipnorton42@gmail.com
--FILE--
<?php
$array = new SplFixedArray(new SplFixedArray(3));
var_dump($array);
try {
$array = new SplFixedArray(new SplFixedArray(3));
}
catch(InvalidArgumentException $iae) {
echo "Ok - ".$iae->getMessage().PHP_EOL;
}
?>
--EXPECTF--
Warning: SplFixedArray::__construct() expects parameter 1 to be integer, object given in %s on line %d
object(SplFixedArray)#1 (0) {
}
Ok - SplFixedArray::__construct() expects parameter 1 to be integer, object given

10
ext/spl/tests/fixedarray_005.phpt

@ -5,8 +5,14 @@ SPL: FixedArray: Trying to instantiate passing object to constructor parameter
$b = new stdClass;
$a = new SplFixedArray($b);
try {
$a = new SplFixedArray($b);
}
catch(InvalidArgumentException $iae) {
echo "Ok - ".$iae->getMessage().PHP_EOL;
}
?>
--EXPECTF--
Warning: SplFixedArray::__construct() expects parameter 1 to be integer, object given in %s on line %d
Ok - SplFixedArray::__construct() expects parameter 1 to be integer, object given

10
ext/spl/tests/fixedarray_009.phpt

@ -3,8 +3,12 @@ SPL: FixedArray: Trying to instantiate passing string to construtor parameter
--FILE--
<?php
$a = new SplFixedArray('FOO');
try {
$a = new SplFixedArray('FOO');
}
catch(InvalidArgumentException $iae) {
echo "Ok - ".$iae->getMessage().PHP_EOL;
}
?>
--EXPECTF--
Warning: SplFixedArray::__construct() expects parameter 1 to be integer, string given in %s on line %d
Ok - SplFixedArray::__construct() expects parameter 1 to be integer, string given

40
ext/spl/tests/fixedarray_015.phpt

@ -3,47 +3,15 @@ SPL: FixedArray: accessing uninitialized array
--FILE--
<?php
$a = new SplFixedArray('');
try {
var_dump($a[1]);
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
try {
$a[1] = 1;
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
try {
var_dump(count($a[1]));
} catch (Exception $e) {
echo $e->getMessage(), "\n";
$a = new SplFixedArray('');
}
try {
var_dump($a->getSize());
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
try {
foreach ($a as $v) {
}
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
try {
var_dump($a->setSize(10));
} catch (Exception $e) {
echo $e->getMessage(), "\n";
catch(InvalidArgumentException $iae) {
echo "Ok - ".$iae->getMessage().PHP_EOL;
}
echo "Done\n";
?>
--EXPECTF--
Warning: SplFixedArray::__construct() expects parameter 1 to be integer, string given in %s on line %d
Index invalid or out of range
Index invalid or out of range
Index invalid or out of range
int(0)
bool(true)
Ok - SplFixedArray::__construct() expects parameter 1 to be integer, string given
Done
Loading…
Cancel
Save