Skip to content

Commit 974183c

Browse files
committed
Convert some SPL Exceptions to normal Errors in spl_iterators.c
1 parent 09767d7 commit 974183c

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
@@ -855,7 +855,7 @@ SPL_METHOD(RecursiveIteratorIterator, setMaxDepth)
855855
RETURN_THROWS();
856856
}
857857
if (max_depth < -1) {
858-
zend_throw_exception(spl_ce_OutOfRangeException, "Parameter max_depth must be >= -1", 0);
858+
zend_value_error("Parameter max_depth must be greater or equal than -1");
859859
RETURN_THROWS();
860860
} else if (max_depth > INT_MAX) {
861861
max_depth = INT_MAX;
@@ -1105,7 +1105,7 @@ SPL_METHOD(RecursiveTreeIterator, setPrefixPart)
11051105
}
11061106

11071107
if (0 > part || part > 5) {
1108-
zend_throw_exception_ex(spl_ce_OutOfRangeException, 0, "Use RecursiveTreeIterator::PREFIX_* constant");
1108+
zend_value_error("Use RecursiveTreeIterator::PREFIX_* constant");
11091109
RETURN_THROWS();
11101110
}
11111111

@@ -1407,11 +1407,11 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
14071407
return NULL;
14081408
}
14091409
if (intern->u.limit.offset < 0) {
1410-
zend_throw_exception(spl_ce_OutOfRangeException, "Parameter offset must be >= 0", 0);
1410+
zend_value_error("Parameter offset must be >= 0");
14111411
return NULL;
14121412
}
14131413
if (intern->u.limit.count < 0 && intern->u.limit.count != -1) {
1414-
zend_throw_exception(spl_ce_OutOfRangeException, "Parameter count must either be -1 or a value greater than or equal 0", 0);
1414+
zend_value_error("Parameter count must either be -1 or a value greater than or equal 0");
14151415
return NULL;
14161416
}
14171417
break;
@@ -1423,7 +1423,7 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
14231423
return NULL;
14241424
}
14251425
if (spl_cit_check_flags(flags) != SUCCESS) {
1426-
zend_throw_exception(spl_ce_InvalidArgumentException, "Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER", 0);
1426+
zend_value_error("Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER");
14271427
return NULL;
14281428
}
14291429
intern->u.caching.flags |= flags & CIT_PUBLIC;
@@ -1444,7 +1444,7 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
14441444
|| !instanceof_function(ce, ce_cast)
14451445
|| !ce_cast->get_iterator
14461446
) {
1447-
zend_throw_exception(spl_ce_LogicException, "Class to downcast to not found or not base class or does not implement Traversable", 0);
1447+
zend_type_error("Class to downcast to not found or not base class or does not implement Traversable");
14481448
return NULL;
14491449
}
14501450
ce = ce_cast;
@@ -1456,7 +1456,7 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
14561456
return NULL;
14571457
}
14581458
if (Z_TYPE(retval) != IS_OBJECT || !instanceof_function(Z_OBJCE(retval), zend_ce_traversable)) {
1459-
zend_throw_exception_ex(spl_ce_LogicException, 0, "%s::getIterator() must return an object that implements Traversable", ZSTR_VAL(ce->name));
1459+
zend_type_error("%s::getIterator() must return an object that implements Traversable", ZSTR_VAL(ce->name));
14601460
return NULL;
14611461
}
14621462
zobject = &retval;
@@ -1485,7 +1485,7 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
14851485
return NULL;
14861486
}
14871487
if (mode < 0 || mode >= REGIT_MODE_MAX) {
1488-
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Illegal mode " ZEND_LONG_FMT, mode);
1488+
zend_value_error("Illegal mode " ZEND_LONG_FMT, mode);
14891489
return NULL;
14901490
}
14911491
intern->u.regex.mode = mode;
@@ -2079,7 +2079,7 @@ SPL_METHOD(RegexIterator, setMode)
20792079
}
20802080

20812081
if (mode < 0 || mode >= REGIT_MODE_MAX) {
2082-
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Illegal mode " ZEND_LONG_FMT, mode);
2082+
zend_value_error("Illegal mode " ZEND_LONG_FMT, mode);
20832083
RETURN_THROWS();
20842084
}
20852085

@@ -2876,7 +2876,7 @@ SPL_METHOD(CachingIterator, setFlags)
28762876
}
28772877

28782878
if (spl_cit_check_flags(flags) != SUCCESS) {
2879-
zend_throw_exception(spl_ce_InvalidArgumentException , "Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER", 0);
2879+
zend_value_error("Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER");
28802880
RETURN_THROWS();
28812881
}
28822882
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)