Skip to content

Commit 5d2fba0

Browse files
committed
Throw exception for unconstructed intl objects
1 parent 0f89d40 commit 5d2fba0

33 files changed

+144
-148
lines changed

ext/intl/breakiterator/breakiterator_class.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ static inline BreakIterator_object *php_intl_breakiterator_fetch_object(zend_obj
5858
BREAKITER_METHOD_FETCH_OBJECT_NO_CHECK; \
5959
if (bio->biter == NULL) \
6060
{ \
61-
intl_errors_set(&bio->err, U_ILLEGAL_ARGUMENT_ERROR, "Found unconstructed BreakIterator", 0); \
62-
RETURN_FALSE; \
61+
zend_throw_error(NULL, "Found unconstructed BreakIterator"); \
62+
RETURN_THROWS(); \
6363
}
6464

6565
void breakiterator_object_create(zval *object, BreakIterator *break_iter, int brand_new);

ext/intl/calendar/calendar_class.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ static inline Calendar_object *php_intl_calendar_fetch_object(zend_object *obj)
5555
CALENDAR_METHOD_FETCH_OBJECT_NO_CHECK; \
5656
if (co->ucal == NULL) \
5757
{ \
58-
intl_errors_set(&co->err, U_ILLEGAL_ARGUMENT_ERROR, "Found unconstructed IntlCalendar", 0); \
59-
RETURN_FALSE; \
58+
zend_throw_error(NULL, "Found unconstructed IntlCalendar"); \
59+
RETURN_THROWS(); \
6060
}
6161

6262
void calendar_object_create(zval *object, Calendar *calendar);

ext/intl/common/common_enum.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ extern "C" {
4141
object = ZEND_THIS; \
4242
INTLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK; \
4343
if (ii->iterator == NULL) { \
44-
intl_errors_set(&ii->err, U_ILLEGAL_ARGUMENT_ERROR, "Found unconstructed IntlIterator", 0); \
45-
RETURN_FALSE; \
44+
zend_throw_error(NULL, "Found unconstructed IntlIterator"); \
45+
RETURN_THROWS(); \
4646
}
4747

4848
typedef struct {

ext/intl/dateformat/dateformat_class.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ extern zend_class_entry *IntlDateFormatter_ce_ptr;
4646
DATE_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK; \
4747
if (dfo->datef_data.udatf == NULL) \
4848
{ \
49-
intl_errors_set(&dfo->datef_data.error, U_ILLEGAL_ARGUMENT_ERROR, "Found unconstructed IntlDateFormatter", 0); \
50-
RETURN_FALSE; \
49+
zend_throw_error(NULL, "Found unconstructed IntlDateFormatter"); \
50+
RETURN_THROWS(); \
5151
}
5252

5353
#define DATE_FORMAT_OBJECT(dfo) (dfo)->datef_data.udatf

ext/intl/formatter/formatter_class.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ extern zend_class_entry *NumberFormatter_ce_ptr;
4444
FORMATTER_METHOD_FETCH_OBJECT_NO_CHECK; \
4545
if (FORMATTER_OBJECT(nfo) == NULL) \
4646
{ \
47-
intl_errors_set(&nfo->nf_data.error, U_ILLEGAL_ARGUMENT_ERROR, \
48-
"Found unconstructed NumberFormatter", 0); \
49-
RETURN_FALSE; \
47+
zend_throw_error(NULL, "Found unconstructed NumberFormatter"); \
48+
RETURN_THROWS(); \
5049
}
5150

5251

ext/intl/msgformat/msgformat_class.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ extern zend_class_entry *MessageFormatter_ce_ptr;
4646
#define MSG_FORMAT_METHOD_FETCH_OBJECT \
4747
MSG_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK; \
4848
if (MSG_FORMAT_OBJECT(mfo) == NULL) { \
49-
intl_errors_set(&mfo->mf_data.error, U_ILLEGAL_ARGUMENT_ERROR, \
50-
"Found unconstructed MessageFormatter", 0); \
51-
RETURN_FALSE; \
49+
zend_throw_error(NULL, "Found unconstructed MessageFormatter"); \
50+
RETURN_THROWS(); \
5251
}
5352

5453
#define MSG_FORMAT_OBJECT(mfo) (mfo)->mf_data.umsgf

ext/intl/resourcebundle/resourcebundle.stub.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static function create(?string $locale, ?string $bundlename, bool $fallba
1313
*/
1414
public function get($index, bool $fallback = true) {}
1515

16-
/** @return int|false */
16+
/** @return int */
1717
public function count() {}
1818

1919
/** @return array|false */
@@ -34,7 +34,7 @@ function resourcebundle_create(?string $locale, ?string $bundlename, bool $fallb
3434
*/
3535
function resourcebundle_get(ResourceBundle $bundle, $index) {}
3636

37-
function resourcebundle_count(ResourceBundle $bundle): int|false {}
37+
function resourcebundle_count(ResourceBundle $bundle): int {}
3838

3939
function resourcebundle_locales(string $bundlename): array|false {}
4040

ext/intl/resourcebundle/resourcebundle_arginfo.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,15 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_resourcebundle_get, 0, 0, 2)
3535
ZEND_ARG_INFO(0, index)
3636
ZEND_END_ARG_INFO()
3737

38-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_resourcebundle_count, 0, 1, MAY_BE_LONG|MAY_BE_FALSE)
38+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_resourcebundle_count, 0, 1, IS_LONG, 0)
3939
ZEND_ARG_OBJ_INFO(0, bundle, ResourceBundle, 0)
4040
ZEND_END_ARG_INFO()
4141

4242
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_resourcebundle_locales, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE)
4343
ZEND_ARG_TYPE_INFO(0, bundlename, IS_STRING, 0)
4444
ZEND_END_ARG_INFO()
4545

46-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_resourcebundle_get_error_code, 0, 1, IS_LONG, 0)
47-
ZEND_ARG_OBJ_INFO(0, bundle, ResourceBundle, 0)
48-
ZEND_END_ARG_INFO()
46+
#define arginfo_resourcebundle_get_error_code arginfo_resourcebundle_count
4947

5048
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_resourcebundle_get_error_message, 0, 1, IS_STRING, 0)
5149
ZEND_ARG_OBJ_INFO(0, bundle, ResourceBundle, 0)

ext/intl/resourcebundle/resourcebundle_class.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,12 @@ static inline ResourceBundle_object *php_intl_resourcebundle_fetch_object(zend_o
3838
#define RESOURCEBUNDLE_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(ResourceBundle, rb)
3939
#define RESOURCEBUNDLE_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(INTL_RESOURCEBUNDLE, rb)
4040
#define RESOURCEBUNDLE_METHOD_FETCH_OBJECT \
41-
INTL_METHOD_FETCH_OBJECT(INTL_RESOURCEBUNDLE, rb); \
41+
INTL_METHOD_FETCH_OBJECT(INTL_RESOURCEBUNDLE, rb); \
4242
if (RESOURCEBUNDLE_OBJECT(rb) == NULL) { \
43-
intl_errors_set(&rb->error, U_ILLEGAL_ARGUMENT_ERROR, \
44-
"Found unconstructed ResourceBundle", 0); \
45-
RETURN_FALSE; \
43+
zend_throw_error(NULL, "Found unconstructed ResourceBundle"); \
44+
RETURN_THROWS(); \
4645
}
4746

48-
4947
#define RESOURCEBUNDLE_OBJECT(rb) (rb)->me
5048

5149
void resourcebundle_register_class( void );

ext/intl/spoofchecker/spoofchecker.stub.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ public function isSuspicious(string $text, &$error = null) {}
1010
/** @return bool */
1111
public function areConfusable(string $s1, string $s2, &$error = null) {}
1212

13-
/** @return null|false */
13+
/** @return void */
1414
public function setAllowedLocales(string $locale_list) {}
1515

16-
/** @return null|false */
16+
/** @return void */
1717
public function setChecks(int $checks) {}
1818

1919
#if U_ICU_VERSION_MAJOR_NUM >= 58
20-
/** @return null|false */
20+
/** @return void */
2121
public function setRestrictionLevel(int $level) {}
2222
#endif
2323
}

ext/intl/spoofchecker/spoofchecker_class.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ extern zend_class_entry *Spoofchecker_ce_ptr;
6363
#define SPOOFCHECKER_METHOD_FETCH_OBJECT \
6464
SPOOFCHECKER_METHOD_FETCH_OBJECT_NO_CHECK; \
6565
if (co->uspoof == NULL) { \
66-
intl_errors_set(&co->err, U_ILLEGAL_ARGUMENT_ERROR, \
67-
"Found unconstructed Spoofchecker", 0); \
68-
RETURN_FALSE; \
66+
zend_throw_error(NULL, "Found unconstructed Spoofchecker"); \
67+
RETURN_THROWS(); \
6968
}
7069

7170
// Macro to check return value of a ucol_* function call.

ext/intl/tests/symfony_format_type_double_intl1.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ $unit_test_args = unserialize('a:3:{i:0;O:15:"NumberFormatter":0:{}i:1;i:1;i:2;s
1212
var_dump($unit_test_args);
1313

1414
// execute the code from #testFormatTypeDoubleIntl
15-
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_DOUBLE);
16-
17-
echo "== didn't crash ==".PHP_EOL;
18-
19-
?>
15+
try {
16+
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_DOUBLE);
17+
} catch (Error $exception) {
18+
echo $exception->getMessage() . "\n";
19+
}
2020
--EXPECT--
2121
array(3) {
2222
[0]=>
@@ -27,4 +27,4 @@ array(3) {
2727
[2]=>
2828
string(1) "1"
2929
}
30-
== didn't crash ==
30+
Found unconstructed NumberFormatter

ext/intl/tests/symfony_format_type_double_intl2.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ $unit_test_args = unserialize('a:3:{i:0;O:15:"NumberFormatter":0:{}i:1;d:1.10000
1212
var_dump($unit_test_args);
1313

1414
// execute the code from #testFormatTypeDoubleIntl
15-
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_DOUBLE);
16-
17-
echo "== didn't crash ==".PHP_EOL;
18-
19-
?>
15+
try {
16+
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_DOUBLE);
17+
} catch (Error $exception) {
18+
echo $exception->getMessage() . "\n";
19+
}
2020
--EXPECT--
2121
array(3) {
2222
[0]=>
@@ -27,4 +27,4 @@ array(3) {
2727
[2]=>
2828
string(3) "1.1"
2929
}
30-
== didn't crash ==
30+
Found unconstructed NumberFormatter

ext/intl/tests/symfony_format_type_double_intl3.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ $unit_test_args = unserialize('a:3:{i:0;O:15:"NumberFormatter":0:{}i:1;i:1;i:2;s
1212
var_dump($unit_test_args);
1313

1414
// execute the code from #testFormatTypeDoubleIntl
15-
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_DOUBLE);
16-
17-
echo "== didn't crash ==".PHP_EOL;
18-
19-
?>
15+
try {
16+
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_DOUBLE);
17+
} catch (Error $exception) {
18+
echo $exception->getMessage() . "\n";
19+
}
2020
--EXPECT--
2121
array(3) {
2222
[0]=>
@@ -27,4 +27,4 @@ array(3) {
2727
[2]=>
2828
string(7) "SFD1.00"
2929
}
30-
== didn't crash ==
30+
Found unconstructed NumberFormatter

ext/intl/tests/symfony_format_type_double_intl4.phpt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ $unit_test_args = unserialize('a:3:{i:0;O:15:"NumberFormatter":0:{}i:1;d:1.10000
1212
var_dump($unit_test_args);
1313

1414
// execute the code from #testFormatTypeDoubleIntl
15-
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_DOUBLE);
16-
17-
echo "== didn't crash ==".PHP_EOL;
18-
15+
try {
16+
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_DOUBLE);
17+
} catch (Error $exception) {
18+
echo $exception->getMessage() . "\n";
19+
}
1920
?>
2021
--EXPECT--
2122
array(3) {
@@ -27,4 +28,4 @@ array(3) {
2728
[2]=>
2829
string(7) "SFD1.10"
2930
}
30-
== didn't crash ==
31+
Found unconstructed NumberFormatter

ext/intl/tests/symfony_format_type_int32_intl1.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ $unit_test_args = unserialize('a:3:{i:0;O:15:"NumberFormatter":0:{}i:1;i:1;i:2;s
3131
var_dump($unit_test_args);
3232

3333
// execute the code from #testFormatTypeInt32Intl
34-
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32);
35-
36-
echo "== didn't crash ==".PHP_EOL;
37-
38-
?>
34+
try {
35+
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32);
36+
} catch (Error $exception) {
37+
echo $exception->getMessage() . "\n";
38+
}
3939
--EXPECT--
4040
array(3) {
4141
[0]=>
@@ -46,4 +46,4 @@ array(3) {
4646
[2]=>
4747
string(1) "1"
4848
}
49-
== didn't crash ==
49+
Found unconstructed NumberFormatter

ext/intl/tests/symfony_format_type_int32_intl2.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ $unit_test_args = unserialize('a:3:{i:0;O:15:"NumberFormatter":0:{}i:1;d:1.10000
1515
var_dump($unit_test_args);
1616

1717
// execute the code from #testFormatTypeInt32Intl
18-
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32);
19-
20-
echo "== didn't crash ==".PHP_EOL;
21-
22-
?>
18+
try {
19+
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32);
20+
} catch (Error $exception) {
21+
echo $exception->getMessage() . "\n";
22+
}
2323
--EXPECT--
2424
array(3) {
2525
[0]=>
@@ -30,4 +30,4 @@ array(3) {
3030
[2]=>
3131
string(1) "1"
3232
}
33-
== didn't crash ==
33+
Found unconstructed NumberFormatter

ext/intl/tests/symfony_format_type_int32_intl3.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ $unit_test_args = unserialize('a:4:{i:0;O:15:"NumberFormatter":0:{}i:1;d:2147483
1212
var_dump($unit_test_args);
1313

1414
// execute the code from #testFormatTypeInt32Intl
15-
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32);
16-
17-
echo "== didn't crash ==".PHP_EOL;
18-
19-
?>
15+
try {
16+
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32);
17+
} catch (Error $exception) {
18+
echo $exception->getMessage() . "\n";
19+
}
2020
--EXPECT--
2121
array(4) {
2222
[0]=>
@@ -29,4 +29,4 @@ array(4) {
2929
[3]=>
3030
string(83) "->format() TYPE_INT32 formats inconsistently an integer if out of the 32 bit range."
3131
}
32-
== didn't crash ==
32+
Found unconstructed NumberFormatter

ext/intl/tests/symfony_format_type_int32_intl4.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ $unit_test_args = unserialize('a:3:{i:0;O:15:"NumberFormatter":0:{}i:1;i:1;i:2;s
1212
var_dump($unit_test_args);
1313

1414
// execute the code from #testFormatTypeInt32Intl
15-
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32);
16-
17-
echo "== didn't crash ==".PHP_EOL;
18-
19-
?>
15+
try {
16+
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32);
17+
} catch (Error $exception) {
18+
echo $exception->getMessage() . "\n";
19+
}
2020
--EXPECT--
2121
array(3) {
2222
[0]=>
@@ -27,4 +27,4 @@ array(3) {
2727
[2]=>
2828
string(7) "SFD1.00"
2929
}
30-
== didn't crash ==
30+
Found unconstructed NumberFormatter

ext/intl/tests/symfony_format_type_int32_intl5.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ $unit_test_args = unserialize('a:3:{i:0;O:15:"NumberFormatter":0:{}i:1;d:1.10000
1212
var_dump($unit_test_args);
1313

1414
// execute the code from #testFormatTypeInt32Intl
15-
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32);
16-
17-
echo "== didn't crash ==".PHP_EOL;
18-
19-
?>
15+
try {
16+
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32);
17+
} catch (Error $exception) {
18+
echo $exception->getMessage() . "\n";
19+
}
2020
--EXPECT--
2121
array(3) {
2222
[0]=>
@@ -27,4 +27,4 @@ array(3) {
2727
[2]=>
2828
string(7) "SFD1.00"
2929
}
30-
== didn't crash ==
30+
Found unconstructed NumberFormatter

ext/intl/tests/symfony_format_type_int32_intl6.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ $unit_test_args = unserialize('a:4:{i:0;O:15:"NumberFormatter":0:{}i:1;d:2147483
1212
var_dump($unit_test_args);
1313

1414
// execute the code from #testFormatTypeInt32Intl
15-
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32);
16-
17-
echo "== didn't crash ==".PHP_EOL;
18-
19-
?>
15+
try {
16+
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32);
17+
} catch (Error $exception) {
18+
echo $exception->getMessage() . "\n";
19+
}
2020
--EXPECT--
2121
array(4) {
2222
[0]=>
@@ -29,4 +29,4 @@ array(4) {
2929
[3]=>
3030
string(83) "->format() TYPE_INT32 formats inconsistently an integer if out of the 32 bit range."
3131
}
32-
== didn't crash ==
32+
Found unconstructed NumberFormatter

0 commit comments

Comments
 (0)