Skip to content

Commit de41cf3

Browse files
committed
Convert some SPL Exceptions to normal Errors in spl_iterators.c
1 parent 2bc3e07 commit de41cf3

8 files changed

+74
-85
lines changed

ext/spl/spl_iterators.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ SPL_METHOD(RecursiveIteratorIterator, setMaxDepth)
848848
RETURN_THROWS();
849849
}
850850
if (max_depth < -1) {
851-
zend_throw_exception(spl_ce_OutOfRangeException, "Parameter max_depth must be >= -1", 0);
851+
zend_value_error("Parameter max_depth must be greater or equal than -1");
852852
RETURN_THROWS();
853853
} else if (max_depth > INT_MAX) {
854854
max_depth = INT_MAX;
@@ -1084,7 +1084,7 @@ SPL_METHOD(RecursiveTreeIterator, setPrefixPart)
10841084
}
10851085

10861086
if (0 > part || part > 5) {
1087-
zend_throw_exception_ex(spl_ce_OutOfRangeException, 0, "Use RecursiveTreeIterator::PREFIX_* constant");
1087+
zend_value_error("Use RecursiveTreeIterator::PREFIX_* constant");
10881088
RETURN_THROWS();
10891089
}
10901090

@@ -1370,11 +1370,11 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
13701370
return NULL;
13711371
}
13721372
if (intern->u.limit.offset < 0) {
1373-
zend_throw_exception(spl_ce_OutOfRangeException, "Parameter offset must be >= 0", 0);
1373+
zend_value_error("Parameter offset must be >= 0");
13741374
return NULL;
13751375
}
13761376
if (intern->u.limit.count < 0 && intern->u.limit.count != -1) {
1377-
zend_throw_exception(spl_ce_OutOfRangeException, "Parameter count must either be -1 or a value greater than or equal 0", 0);
1377+
zend_value_error("Parameter count must either be -1 or a value greater than or equal 0");
13781378
return NULL;
13791379
}
13801380
break;
@@ -1386,7 +1386,7 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
13861386
return NULL;
13871387
}
13881388
if (spl_cit_check_flags(flags) != SUCCESS) {
1389-
zend_throw_exception(spl_ce_InvalidArgumentException, "Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER", 0);
1389+
zend_value_error("Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER");
13901390
return NULL;
13911391
}
13921392
intern->u.caching.flags |= flags & CIT_PUBLIC;
@@ -1407,7 +1407,7 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
14071407
|| !instanceof_function(ce, ce_cast)
14081408
|| !ce_cast->get_iterator
14091409
) {
1410-
zend_throw_exception(spl_ce_LogicException, "Class to downcast to not found or not base class or does not implement Traversable", 0);
1410+
zend_type_error("Class to downcast to not found or not base class or does not implement Traversable");
14111411
return NULL;
14121412
}
14131413
ce = ce_cast;
@@ -1419,7 +1419,7 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
14191419
return NULL;
14201420
}
14211421
if (Z_TYPE(retval) != IS_OBJECT || !instanceof_function(Z_OBJCE(retval), zend_ce_traversable)) {
1422-
zend_throw_exception_ex(spl_ce_LogicException, 0, "%s::getIterator() must return an object that implements Traversable", ZSTR_VAL(ce->name));
1422+
zend_type_error("%s::getIterator() must return an object that implements Traversable", ZSTR_VAL(ce->name));
14231423
return NULL;
14241424
}
14251425
zobject = &retval;
@@ -1451,7 +1451,7 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
14511451
return NULL;
14521452
}
14531453
if (mode < 0 || mode >= REGIT_MODE_MAX) {
1454-
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Illegal mode " ZEND_LONG_FMT, mode);
1454+
zend_value_error("Illegal mode " ZEND_LONG_FMT, mode);
14551455
return NULL;
14561456
}
14571457
intern->u.regex.mode = mode;
@@ -2045,7 +2045,7 @@ SPL_METHOD(RegexIterator, setMode)
20452045
}
20462046

20472047
if (mode < 0 || mode >= REGIT_MODE_MAX) {
2048-
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Illegal mode " ZEND_LONG_FMT, mode);
2048+
zend_value_error("Illegal mode " ZEND_LONG_FMT, mode);
20492049
RETURN_THROWS();
20502050
}
20512051

@@ -2804,7 +2804,7 @@ SPL_METHOD(CachingIterator, setFlags)
28042804
SPL_FETCH_AND_CHECK_DUAL_IT(intern, ZEND_THIS);
28052805

28062806
if (spl_cit_check_flags(flags) != SUCCESS) {
2807-
zend_throw_exception(spl_ce_InvalidArgumentException , "Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER", 0);
2807+
zend_value_error("Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER");
28082808
RETURN_THROWS();
28092809
}
28102810
if ((intern->u.caching.flags & CIT_CALL_TOSTRING) != 0 && (flags & CIT_CALL_TOSTRING) == 0) {

ext/spl/tests/bug51119.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ try {
2020
foreach ($limitIterator as $item) {
2121
echo $item . "\n";
2222
}
23-
} catch (OutOfRangeException $e){
24-
print $e->getMessage() . "\n";
23+
} catch (\ValueError $e){
24+
echo $e->getMessage() . PHP_EOL;
2525
}
2626

2727
?>

ext/spl/tests/iterator_028.phpt

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,12 @@ foreach($it as $v) echo $it->getDepth() . ": $v\n";
3939
echo "===-1===\n";
4040
$it->setMaxDepth(-1);
4141
var_dump($it->getMaxDepth());
42-
try
43-
{
44-
$it->setMaxDepth(4);
45-
$it->setMaxDepth(-2);
46-
}
47-
catch(Exception $e)
48-
{
49-
var_dump($e->getMessage());
42+
43+
try {
44+
$it->setMaxDepth(4);
45+
$it->setMaxDepth(-2);
46+
} catch (\ValueError $e) {
47+
echo $e->getMessage() . PHP_EOL;
5048
}
5149
var_dump($it->getMaxDepth());
5250
?>
@@ -105,5 +103,5 @@ int(0)
105103
0: 4
106104
===-1===
107105
bool(false)
108-
string(33) "Parameter max_depth must be >= -1"
106+
Parameter max_depth must be greater or equal than -1
109107
int(4)

ext/spl/tests/iterator_037.phpt

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,27 @@ SPL: CachingIterator and __toString
55

66
function test($ar, $flags)
77
{
8-
echo "===$flags===\n";
9-
$it = new CachingIterator($ar, 0);
10-
try
11-
{
12-
$it->setFlags($flags);
13-
}
14-
catch (Exception $e)
15-
{
16-
echo 'Exception: ' . $e->getMessage() . "\n";
17-
var_dump($it->getFlags());
18-
return;
19-
}
20-
var_dump($it->getFlags());
21-
try
22-
{
23-
foreach($it as $v)
24-
{
25-
var_dump((string)$it);
26-
}
27-
}
28-
catch (Exception $e)
29-
{
30-
echo 'Exception: ' . $e->getMessage() . "\n";
8+
echo "===$flags===\n";
9+
$it = new CachingIterator($ar, 0);
10+
try {
11+
$it->setFlags($flags);
12+
} catch (\ValueError $e) {
13+
echo $e->getMessage() . PHP_EOL;
14+
var_dump($it->getFlags());
15+
return;
3116
}
17+
var_dump($it->getFlags());
18+
try
19+
{
20+
foreach($it as $v)
21+
{
22+
var_dump((string)$it);
23+
}
24+
}
25+
catch (Exception $e)
26+
{
27+
echo 'Exception: ' . $e->getMessage() . "\n";
28+
}
3229
}
3330

3431
class MyItem
@@ -110,19 +107,19 @@ string(3) "0:1"
110107
string(3) "1:2"
111108
string(3) "2:3"
112109
===3===
113-
Exception: Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER
110+
Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER
114111
int(0)
115112
===5===
116-
Exception: Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER
113+
Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER
117114
int(0)
118115
===9===
119-
Exception: Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER
116+
Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER
120117
int(0)
121118
===6===
122-
Exception: Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER
119+
Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER
123120
int(0)
124121
===10===
125-
Exception: Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER
122+
Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER
126123
int(0)
127124
===X===
128125
Exception: Unsetting flag CALL_TO_STRING is not possible

ext/spl/tests/recursive_tree_iterator_008.phpt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,23 @@ for($i = 0; $i < 6; ++$i) {
1818
foreach($it as $k => $v) {
1919
echo "[$k] => $v\n";
2020
}
21+
2122
try {
22-
$it->setPrefixPart(-1, "");
23-
$it->setPrefixPart(6, "");
24-
} catch (OutOfRangeException $e) {
25-
echo "OutOfRangeException thrown\n";
23+
$it->setPrefixPart(-1, "");
24+
$it->setPrefixPart(6, "");
25+
} catch (\ValueError $e) {
26+
echo $e->getMessage() . PHP_EOL;
2627
}
2728
try {
28-
$it->setPrefixPart(6, "");
29-
} catch (OutOfRangeException $e) {
30-
echo "OutOfRangeException thrown\n";
29+
$it->setPrefixPart(6, "");
30+
} catch (\ValueError $e) {
31+
echo $e->getMessage() . PHP_EOL;
3132
}
3233
?>
3334
--EXPECT--
3435
[a] => 035Array
3536
[0] => 0145b
3637
[c] => 045Array
3738
[0] => 0245d
38-
OutOfRangeException thrown
39-
OutOfRangeException thrown
39+
Use RecursiveTreeIterator::PREFIX_* constant
40+
Use RecursiveTreeIterator::PREFIX_* constant

ext/spl/tests/regexIterator_setMode_error.phpt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@ $regexIterator = new RegexIterator(new ArrayIterator($array), "/f/");
1111
var_dump($regexIterator->getMode());
1212

1313
try {
14-
$regexIterator->setMode(7);
15-
} catch (InvalidArgumentException $e) {
16-
var_dump($e->getMessage());
17-
var_dump($e->getCode());
14+
$regexIterator->setMode(7);
15+
} catch (\ValueError $e) {
16+
echo $e->getMessage() . PHP_EOL;
1817
}
1918

2019
?>
21-
--EXPECTF--
22-
int(0)
23-
string(14) "Illegal mode 7"
20+
--EXPECT--
2421
int(0)
22+
Illegal mode 7

ext/spl/tests/spl_caching_iterator_constructor_flags.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ TestFest London May 2009
88
//line 681 ...
99
$array = array(array(7,8,9),1,2,3,array(4,5,6));
1010
$arrayIterator = new ArrayIterator($array);
11-
try {
1211
$test = new CachingIterator($arrayIterator, 0);
1312
$test = new CachingIterator($arrayIterator, 1);
1413
$test = new CachingIterator($arrayIterator, 2);
15-
$test = new CachingIterator($arrayIterator, 3); // this throws an exception
16-
} catch (InvalidArgumentException $e){
17-
print $e->getMessage() . "\n";
18-
}
1914

15+
try {
16+
$test = new CachingIterator($arrayIterator, 3); // this throws an exception
17+
} catch (\ValueError $e) {
18+
echo $e->getMessage() . PHP_EOL;
19+
}
2020

2121
?>
2222
--EXPECT--

ext/spl/tests/spl_limit_iterator_check_limits.phpt

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,22 @@ TestFest London May 2009
99
$arrayIterator = new ArrayIterator($array);
1010

1111
try {
12-
$limitIterator = new LimitIterator($arrayIterator, -1);
13-
} catch (OutOfRangeException $e){
14-
print $e->getMessage(). "\n";
12+
var_dump(new LimitIterator($arrayIterator, -1));
13+
} catch (\ValueError $e) {
14+
echo $e->getMessage() . PHP_EOL;
1515
}
1616

17-
1817
try {
19-
$limitIterator = new LimitIterator($arrayIterator, 0, -2);
20-
} catch (OutOfRangeException $e){
21-
print $e->getMessage() . "\n";
18+
var_dump(new LimitIterator($arrayIterator, 0, -2));
19+
} catch (\ValueError $e) {
20+
echo $e->getMessage() . PHP_EOL;
2221
}
2322

24-
try {
25-
$limitIterator = new LimitIterator($arrayIterator, 0, -1);
26-
} catch (OutOfRangeException $e){
27-
print $e->getMessage() . "\n";
28-
}
29-
30-
23+
var_dump(new LimitIterator($arrayIterator, 0, -1));
3124

3225
?>
33-
--EXPECT--
26+
--EXPECTF--
3427
Parameter offset must be >= 0
3528
Parameter count must either be -1 or a value greater than or equal 0
29+
object(LimitIterator)#%d (%d) {
30+
}

0 commit comments

Comments
 (0)