Skip to content

Commit 9155a26

Browse files
committed
Merge branch 'InternalClassClean' of github.com:Danack/php-src into InternalClassClean
* 'InternalClassClean' of github.com:Danack/php-src: Fixed indentation. Fixed comment style. Fixed commented out code. Reverted change to function name and added note of why it is different from the class it is actually changing. Made UConverter throw an exception if the constructor fails. Fixed PDO constructor to not return null. Fixed fileinfo behaviour. Made Phar throw exception on bad constructor. Converted intl extension to use IntlException in constructors. Fixed SplFixedArray and tests. Fixed ReflectionExtension and ReflectionProperty. Fixed ReflectionFunction, ReflectionMethod and ReflectionParameter. Fixed PDORow behaviour and message.
2 parents c71c97e + 910a324 commit 9155a26

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+589
-310
lines changed

ext/fileinfo/fileinfo.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,18 @@ PHP_FUNCTION(finfo_open)
301301
php_fileinfo *finfo;
302302
FILEINFO_DECLARE_INIT_OBJECT(object)
303303
char resolved_path[MAXPATHLEN];
304+
zend_error_handling zeh;
305+
int rv;
304306

305-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|lp", &options, &file, &file_len) == FAILURE) {
307+
if (object) {
308+
zend_replace_error_handling(EH_THROW, NULL, &zeh TSRMLS_CC);
309+
rv = zend_parse_parameters(ZEND_NUM_ARGS(), "|lp", &options, &file, &file_len);
310+
zend_restore_error_handling(&zeh TSRMLS_CC);
311+
} else {
312+
rv = zend_parse_parameters(ZEND_NUM_ARGS(), "|lp", &options, &file, &file_len);
313+
}
314+
315+
if (rv == FAILURE) {
306316
FILEINFO_DESTROY_OBJECT(object);
307317
RETURN_FALSE;
308318
}

ext/intl/breakiterator/breakiterator_methods.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,12 @@ U_CFUNC PHP_FUNCTION(breakiter_set_text)
162162
BREAKITER_METHOD_FETCH_OBJECT;
163163

164164
ut = utext_openUTF8(ut, text->val, text->len, BREAKITER_ERROR_CODE_P(bio));
165-
INTL_CTOR_CHECK_STATUS(bio, "breakiter_set_text: error opening UText");
165+
INTL_CTOR_CHECK_STATUS(bio, "breakiter_set_text: error opening UText", 0);
166166

167167
bio->biter->setText(ut, BREAKITER_ERROR_CODE(bio));
168168
utext_close(ut); /* ICU shallow clones the UText */
169169
INTL_CTOR_CHECK_STATUS(bio, "breakiter_set_text: error calling "
170-
"BreakIterator::setText()");
170+
"BreakIterator::setText()", 0);
171171

172172
/* When ICU clones the UText, it does not copy the buffer, so we have to
173173
* keep the string buffer around by holding a reference to its zval. This

ext/intl/calendar/gregoriancalendar_methods.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static inline GregorianCalendar *fetch_greg(Calendar_object *co) {
3636
return (GregorianCalendar*)co->ucal;
3737
}
3838

39-
static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
39+
static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor)
4040
{
4141
zval *tz_object = NULL;
4242
zval args_a[6] = {0},
@@ -51,18 +51,18 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
5151
// parameter number validation / variant determination
5252
if (ZEND_NUM_ARGS() > 6 ||
5353
zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) {
54-
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
55-
"intlgregcal_create_instance: too many arguments", 0);
54+
intl_error_set_ex(NULL, U_ILLEGAL_ARGUMENT_ERROR,
55+
"intlgregcal_create_instance: too many arguments", 0, is_constructor);
5656
Z_OBJ_P(return_value) = NULL;
5757
return;
5858
}
5959
for (variant = ZEND_NUM_ARGS();
6060
variant > 0 && Z_TYPE(args[variant - 1]) == IS_NULL;
6161
variant--) {}
6262
if (variant == 4) {
63-
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
63+
intl_error_set_ex(NULL, U_ILLEGAL_ARGUMENT_ERROR,
6464
"intlgregcal_create_instance: no variant with 4 arguments "
65-
"(excluding trailing NULLs)", 0);
65+
"(excluding trailing NULLs)", 0, is_constructor);
6666
Z_OBJ_P(return_value) = NULL;
6767
return;
6868
}
@@ -71,17 +71,17 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
7171
if (variant <= 2) {
7272
if (zend_parse_parameters(MIN(ZEND_NUM_ARGS(), 2),
7373
"|z!s!", &tz_object, &locale, &locale_len) == FAILURE) {
74-
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
75-
"intlgregcal_create_instance: bad arguments", 0);
74+
intl_error_set_ex(NULL, U_ILLEGAL_ARGUMENT_ERROR,
75+
"intlgregcal_create_instance: bad arguments", 0, is_constructor);
7676
Z_OBJ_P(return_value) = NULL;
7777
return;
7878
}
7979
}
8080
if (variant > 2 && zend_parse_parameters(ZEND_NUM_ARGS(),
8181
"lll|lll", &largs[0], &largs[1], &largs[2], &largs[3], &largs[4],
8282
&largs[5]) == FAILURE) {
83-
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
84-
"intlgregcal_create_instance: bad arguments", 0);
83+
intl_error_set_ex(NULL, U_ILLEGAL_ARGUMENT_ERROR,
84+
"intlgregcal_create_instance: bad arguments", 0, is_constructor);
8585
Z_OBJ_P(return_value) = NULL;
8686
return;
8787
}
@@ -104,8 +104,8 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
104104
gcal = new GregorianCalendar(tz, Locale::createFromName(locale),
105105
status);
106106
if (U_FAILURE(status)) {
107-
intl_error_set(NULL, status, "intlgregcal_create_instance: error "
108-
"creating ICU GregorianCalendar from time zone and locale", 0);
107+
intl_error_set_ex(NULL, status, "intlgregcal_create_instance: error "
108+
"creating ICU GregorianCalendar from time zone and locale", 0, is_constructor);
109109
if (gcal) {
110110
delete gcal;
111111
}
@@ -117,9 +117,9 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
117117
// From date/time (3, 5 or 6 arguments)
118118
for (int i = 0; i < variant; i++) {
119119
if (largs[i] < INT32_MIN || largs[i] > INT32_MAX) {
120-
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
120+
intl_error_set_ex(NULL, U_ILLEGAL_ARGUMENT_ERROR,
121121
"intlgregcal_create_instance: at least one of the arguments"
122-
" has an absolute value that is too large", 0);
122+
" has an absolute value that is too large", 0, is_constructor);
123123
Z_OBJ_P(return_value) = NULL;
124124
return;
125125
}
@@ -137,8 +137,8 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
137137
status);
138138
}
139139
if (U_FAILURE(status)) {
140-
intl_error_set(NULL, status, "intlgregcal_create_instance: error "
141-
"creating ICU GregorianCalendar from date", 0);
140+
intl_error_set_ex(NULL, status, "intlgregcal_create_instance: error "
141+
"creating ICU GregorianCalendar from date", 0, is_constructor);
142142
if (gcal) {
143143
delete gcal;
144144
}
@@ -154,10 +154,10 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS)
154154
strlen(tzinfo->name), US_INV);
155155
#endif
156156
if (tzstr.isBogus()) {
157-
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
157+
intl_error_set_ex(NULL, U_ILLEGAL_ARGUMENT_ERROR,
158158
"intlgregcal_create_instance: could not create UTF-8 string "
159159
"from PHP's default timezone name (see date_default_timezone_get())",
160-
0);
160+
0, is_constructor);
161161
delete gcal;
162162
Z_OBJ_P(return_value) = NULL;
163163
return;
@@ -179,7 +179,7 @@ U_CFUNC PHP_FUNCTION(intlgregcal_create_instance)
179179
object_init_ex(return_value, GregorianCalendar_ce_ptr);
180180
ZVAL_COPY_VALUE(&orig, return_value);
181181

182-
_php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU);
182+
_php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
183183

184184
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
185185
zval_dtor(&orig);
@@ -194,7 +194,7 @@ U_CFUNC PHP_METHOD(IntlGregorianCalendar, __construct)
194194

195195
return_value = getThis();
196196
//changes this to IS_NULL (without first destroying) if there's an error
197-
_php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU);
197+
_php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
198198

199199
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
200200
zend_object_store_ctor_failed(Z_OBJ(orig_this));

ext/intl/collator/collator_create.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "intl_data.h"
2626

2727
/* {{{ */
28-
static void collator_ctor(INTERNAL_FUNCTION_PARAMETERS)
28+
static void collator_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor)
2929
{
3030
const char* locale;
3131
size_t locale_len = 0;
@@ -38,8 +38,8 @@ static void collator_ctor(INTERNAL_FUNCTION_PARAMETERS)
3838
if( zend_parse_parameters( ZEND_NUM_ARGS(), "s",
3939
&locale, &locale_len ) == FAILURE )
4040
{
41-
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
42-
"collator_create: unable to parse input params", 0 );
41+
intl_error_set_ex( NULL, U_ILLEGAL_ARGUMENT_ERROR,
42+
"collator_create: unable to parse input params", 0, is_constructor );
4343
zval_dtor(return_value);
4444
RETURN_NULL();
4545
}
@@ -53,7 +53,7 @@ static void collator_ctor(INTERNAL_FUNCTION_PARAMETERS)
5353

5454
/* Open ICU collator. */
5555
co->ucoll = ucol_open( locale, COLLATOR_ERROR_CODE_P( co ) );
56-
INTL_CTOR_CHECK_STATUS(co, "collator_create: unable to open ICU collator");
56+
INTL_CTOR_CHECK_STATUS(co, "collator_create: unable to open ICU collator", is_constructor);
5757
}
5858
/* }}} */
5959

@@ -63,7 +63,7 @@ static void collator_ctor(INTERNAL_FUNCTION_PARAMETERS)
6363
PHP_FUNCTION( collator_create )
6464
{
6565
object_init_ex( return_value, Collator_ce_ptr );
66-
collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
66+
collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
6767
}
6868
/* }}} */
6969

@@ -75,7 +75,7 @@ PHP_METHOD( Collator, __construct )
7575
zval orig_this = *getThis();
7676

7777
return_value = getThis();
78-
collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
78+
collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
7979

8080
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
8181
zend_object_store_ctor_failed(Z_OBJ(orig_this));

ext/intl/converter/converter.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <unicode/ustring.h>
2323

2424
#include "../intl_error.h"
25+
#include "../intl_common.h"
2526

2627
typedef struct _php_converter_object {
2728
UConverter *src, *dest;
@@ -556,11 +557,17 @@ static PHP_METHOD(UConverter, __construct) {
556557
size_t src_len = sizeof("utf-8") - 1;
557558
char *dest = src;
558559
size_t dest_len = src_len;
560+
zend_error_handling zeh;
561+
int rv;
559562

560563
intl_error_reset(NULL);
561564

562-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s!",
563-
&dest, &dest_len, &src, &src_len) == FAILURE) {
565+
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &zeh TSRMLS_CC);
566+
rv = zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s!",
567+
&dest, &dest_len, &src, &src_len);
568+
zend_restore_error_handling(&zeh TSRMLS_CC);
569+
570+
if (rv == FAILURE) {
564571
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
565572
"UConverter::__construct(): bad arguments", 0);
566573
return;

ext/intl/dateformat/dateformat_create.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ extern "C" {
3636
#include "dateformat_helpers.h"
3737

3838
/* {{{ */
39-
static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
39+
static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor)
4040
{
4141
zval *object;
4242

@@ -64,8 +64,8 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
6464
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sll|zzs",
6565
&locale_str, &locale_len, &date_type, &time_type, &timezone_zv,
6666
&calendar_zv, &pattern_str, &pattern_str_len) == FAILURE) {
67-
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: "
68-
"unable to parse input parameters", 0);
67+
intl_error_set_ex( NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: "
68+
"unable to parse input parameters", 0, is_constructor);
6969
Z_OBJ_P(return_value) = NULL;
7070
return;
7171
}
@@ -79,6 +79,8 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
7979
DATE_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK;
8080

8181
if (DATE_FORMAT_OBJECT(dfo) != NULL) {
82+
/* This is __construct being called on an instance - it is not
83+
a constructor. */
8284
intl_errors_set(INTL_DATA_ERROR_P(dfo), U_ILLEGAL_ARGUMENT_ERROR,
8385
"datefmt_create: cannot call constructor twice", 0);
8486
return;
@@ -110,8 +112,8 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
110112
pattern_str, pattern_str_len, &INTL_DATA_ERROR_CODE(dfo));
111113
if (U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) {
112114
/* object construction -> only set global error */
113-
intl_error_set(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create: "
114-
"error converting pattern to UTF-16", 0);
115+
intl_error_set_ex(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create: "
116+
"error converting pattern to UTF-16", 0, is_constructor);
115117
goto error;
116118
}
117119
}
@@ -139,8 +141,8 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
139141
df->adoptTimeZone(timezone);
140142
}
141143
} else {
142-
intl_error_set(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create: date "
143-
"formatter creation failed", 0);
144+
intl_error_set_ex(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create: date "
145+
"formatter creation failed", 0, is_constructor);
144146
goto error;
145147
}
146148

@@ -175,7 +177,7 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
175177
U_CFUNC PHP_FUNCTION( datefmt_create )
176178
{
177179
object_init_ex( return_value, IntlDateFormatter_ce_ptr );
178-
datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
180+
datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
179181
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
180182
RETURN_NULL();
181183
}
@@ -192,7 +194,7 @@ U_CFUNC PHP_METHOD( IntlDateFormatter, __construct )
192194
/* return_value param is being changed, therefore we will always return
193195
* NULL here */
194196
return_value = getThis();
195-
datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
197+
datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
196198

197199
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
198200
zend_object_store_ctor_failed(Z_OBJ(orig_this));

ext/intl/formatter/formatter_main.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "intl_convert.h"
2626

2727
/* {{{ */
28-
static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
28+
static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor)
2929
{
3030
const char* locale;
3131
char* pattern = NULL;
@@ -39,8 +39,8 @@ static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
3939
if( zend_parse_parameters( ZEND_NUM_ARGS(), "sl|s",
4040
&locale, &locale_len, &style, &pattern, &pattern_len ) == FAILURE )
4141
{
42-
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
43-
"numfmt_create: unable to parse input parameters", 0 );
42+
intl_error_set_ex( NULL, U_ILLEGAL_ARGUMENT_ERROR,
43+
"numfmt_create: unable to parse input parameters", 0, is_constructor );
4444
Z_OBJ_P(return_value) = NULL;
4545
return;
4646
}
@@ -52,7 +52,7 @@ static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
5252
/* Convert pattern (if specified) to UTF-16. */
5353
if(pattern && pattern_len) {
5454
intl_convert_utf8_to_utf16(&spattern, &spattern_len, pattern, pattern_len, &INTL_DATA_ERROR_CODE(nfo));
55-
INTL_CTOR_CHECK_STATUS(nfo, "numfmt_create: error converting pattern to UTF-16");
55+
INTL_CTOR_CHECK_STATUS(nfo, "numfmt_create: error converting pattern to UTF-16", is_constructor);
5656
}
5757

5858
if(locale_len == 0) {
@@ -66,7 +66,7 @@ static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
6666
efree(spattern);
6767
}
6868

69-
INTL_CTOR_CHECK_STATUS(nfo, "numfmt_create: number formatter creation failed");
69+
INTL_CTOR_CHECK_STATUS(nfo, "numfmt_create: number formatter creation failed", is_constructor);
7070
}
7171
/* }}} */
7272

@@ -78,7 +78,7 @@ static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS)
7878
PHP_FUNCTION( numfmt_create )
7979
{
8080
object_init_ex( return_value, NumberFormatter_ce_ptr );
81-
numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
81+
numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
8282
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
8383
RETURN_NULL();
8484
}
@@ -93,7 +93,7 @@ PHP_METHOD( NumberFormatter, __construct )
9393
zval orig_this = *getThis();
9494

9595
return_value = getThis();
96-
numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
96+
numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
9797

9898
if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
9999
zend_object_store_ctor_failed(Z_OBJ(orig_this));

ext/intl/intl_common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,6 @@
4141
#define INTL_Z_STRVAL_P(str) (UChar*) Z_STRVAL_P(str)
4242
#define INTL_Z_STRLEN_P(str) UCHARS( Z_STRLEN_P(str) )
4343

44+
extern zend_class_entry *IntlException_ce_ptr;
45+
4446
#endif /* INTL_COMMON_H */

ext/intl/intl_data.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ typedef struct _intl_data {
6464
}
6565

6666
/* Check status, if error - destroy value and exit */
67-
#define INTL_CTOR_CHECK_STATUS(obj, msg) \
67+
#define INTL_CTOR_CHECK_STATUS(obj, msg, forceException) \
6868
intl_error_set_code( NULL, INTL_DATA_ERROR_CODE((obj)) ); \
6969
if( U_FAILURE( INTL_DATA_ERROR_CODE((obj)) ) ) \
7070
{ \
71-
intl_errors_set_custom_msg( INTL_DATA_ERROR_P((obj)), msg, 0 ); \
71+
intl_errors_set_custom_msg_ex( INTL_DATA_ERROR_P((obj)), msg, 0, forceException ); \
7272
/* yes, this is ugly, but it alreay is */ \
7373
if (return_value != getThis()) { \
7474
zval_dtor(return_value); \

0 commit comments

Comments
 (0)