Skip to content

Commit b620733

Browse files
committed
Use normal error in SPL for uninitialized objects
1 parent 9affbef commit b620733

File tree

7 files changed

+38
-49
lines changed

7 files changed

+38
-49
lines changed

ext/spl/spl_directory.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@ PHPAPI zend_class_entry *spl_ce_GlobIterator;
5252
PHPAPI zend_class_entry *spl_ce_SplFileObject;
5353
PHPAPI zend_class_entry *spl_ce_SplTempFileObject;
5454

55-
// TODO Use standard Error
5655
#define CHECK_SPL_FILE_OBJECT_IS_INITIALIZED(spl_filesystem_object_pointer) \
5756
if (!(spl_filesystem_object_pointer)->u.file.stream) { \
58-
zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); \
57+
zend_throw_error(NULL, "Object not initialized"); \
5958
RETURN_THROWS(); \
6059
}
6160

@@ -209,7 +208,7 @@ static inline int spl_filesystem_object_get_file_name(spl_filesystem_object *int
209208
case SPL_FS_INFO:
210209
case SPL_FS_FILE:
211210
if (!intern->file_name) {
212-
zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized");
211+
zend_throw_error(NULL, "Object not initialized");
213212
return FAILURE;
214213
}
215214
break;
@@ -1393,9 +1392,7 @@ PHP_METHOD(SplFileInfo, __debugInfo)
13931392
/* {{{ */
13941393
PHP_METHOD(SplFileInfo, _bad_state_ex)
13951394
{
1396-
zend_throw_exception_ex(spl_ce_LogicException, 0,
1397-
"The parent constructor was not called: the object is in an "
1398-
"invalid state ");
1395+
zend_throw_error(NULL, "The parent constructor was not called: the object is in an invalid state");
13991396
}
14001397
/* }}} */
14011398

@@ -2021,7 +2018,7 @@ static int spl_filesystem_file_read_line(zval * this_ptr, spl_filesystem_object
20212018
static void spl_filesystem_file_rewind(zval * this_ptr, spl_filesystem_object *intern) /* {{{ */
20222019
{
20232020
if (!intern->u.file.stream) {
2024-
zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized");
2021+
zend_throw_error(NULL, "Object not initialized");
20252022
return;
20262023
}
20272024
if (-1 == php_stream_rewind(intern->u.file.stream)) {

ext/spl/spl_iterators.c

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ static inline spl_recursive_it_object *spl_recursive_it_from_obj(zend_object *ob
125125
do { \
126126
spl_dual_it_object *it = Z_SPLDUAL_IT_P(objzval); \
127127
if (it->dit_type == DIT_Unknown) { \
128-
zend_throw_exception_ex(spl_ce_LogicException, 0, \
129-
"The object is in an invalid state as the parent constructor was not called"); \
128+
zend_throw_error(NULL, "The object is in an invalid state as the parent constructor was not called"); \
130129
RETURN_THROWS(); \
131130
} \
132131
(var) = it; \
@@ -135,8 +134,7 @@ static inline spl_recursive_it_object *spl_recursive_it_from_obj(zend_object *ob
135134
#define SPL_FETCH_SUB_ELEMENT(var, object, element) \
136135
do { \
137136
if(!(object)->iterators) { \
138-
zend_throw_exception_ex(spl_ce_LogicException, 0, \
139-
"The object is in an invalid state as the parent constructor was not called"); \
137+
zend_throw_error(NULL, "The object is in an invalid state as the parent constructor was not called"); \
140138
return; \
141139
} \
142140
(var) = (object)->iterators[(object)->level].element; \
@@ -145,8 +143,7 @@ static inline spl_recursive_it_object *spl_recursive_it_from_obj(zend_object *ob
145143
#define SPL_FETCH_SUB_ELEMENT_ADDR(var, object, element) \
146144
do { \
147145
if(!(object)->iterators) { \
148-
zend_throw_exception_ex(spl_ce_LogicException, 0, \
149-
"The object is in an invalid state as the parent constructor was not called"); \
146+
zend_throw_error(NULL, "The object is in an invalid state as the parent constructor was not called"); \
150147
RETURN_THROWS(); \
151148
} \
152149
(var) = &(object)->iterators[(object)->level].element; \
@@ -698,8 +695,7 @@ PHP_METHOD(RecursiveIteratorIterator, getSubIterator)
698695
}
699696

700697
if(!object->iterators) {
701-
zend_throw_exception_ex(spl_ce_LogicException, 0,
702-
"The object is in an invalid state as the parent constructor was not called");
698+
zend_throw_error(NULL, "The object is in an invalid state as the parent constructor was not called");
703699
RETURN_THROWS();
704700
}
705701

@@ -1059,8 +1055,7 @@ PHP_METHOD(RecursiveTreeIterator, getPrefix)
10591055
}
10601056

10611057
if(!object->iterators) {
1062-
zend_throw_exception_ex(spl_ce_LogicException, 0,
1063-
"The object is in an invalid state as the parent constructor was not called");
1058+
zend_throw_error(NULL, "The object is in an invalid state as the parent constructor was not called");
10641059
RETURN_THROWS();
10651060
}
10661061

@@ -1092,8 +1087,7 @@ PHP_METHOD(RecursiveTreeIterator, getEntry)
10921087
}
10931088

10941089
if(!object->iterators) {
1095-
zend_throw_exception_ex(spl_ce_LogicException, 0,
1096-
"The object is in an invalid state as the parent constructor was not called");
1090+
zend_throw_error(NULL, "The object is in an invalid state as the parent constructor was not called");
10971091
RETURN_THROWS();
10981092
}
10991093

@@ -1110,8 +1104,7 @@ PHP_METHOD(RecursiveTreeIterator, getPostfix)
11101104
}
11111105

11121106
if(!object->iterators) {
1113-
zend_throw_exception_ex(spl_ce_LogicException, 0,
1114-
"The object is in an invalid state as the parent constructor was not called");
1107+
zend_throw_error(NULL, "The object is in an invalid state as the parent constructor was not called");
11151108
RETURN_THROWS();
11161109
}
11171110

@@ -1131,8 +1124,7 @@ PHP_METHOD(RecursiveTreeIterator, current)
11311124
}
11321125

11331126
if(!object->iterators) {
1134-
zend_throw_exception_ex(spl_ce_LogicException, 0,
1135-
"The object is in an invalid state as the parent constructor was not called");
1127+
zend_throw_error(NULL, "The object is in an invalid state as the parent constructor was not called");
11361128
RETURN_THROWS();
11371129
}
11381130

ext/spl/tests/bug54281.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ foreach($it as $k=>$v) { }
1212

1313
?>
1414
--EXPECTF--
15-
Fatal error: Uncaught LogicException: The object is in an invalid state as the parent constructor was not called in %s:%d
15+
Fatal error: Uncaught Error: The object is in an invalid state as the parent constructor was not called in %s:%d
1616
Stack trace:
1717
#0 %s%ebug54281.php(8): RecursiveIteratorIterator->rewind()
1818
#1 {main}

ext/spl/tests/bug54384.phpt

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ function test($f) {
77
try {
88
$f();
99
echo "ran normally (unexpected)\n\n";
10-
} catch (LogicException $e) {
11-
echo "exception (expected)\n";
10+
} catch (\Error $e) {
11+
echo "Error (expected)\n";
1212
}
1313
}
1414

@@ -154,18 +154,18 @@ echo $a,"\n";
154154
} );
155155
?>
156156
--EXPECT--
157-
IteratorIterator... exception (expected)
158-
FilterIterator... exception (expected)
159-
RecursiveFilterIterator... exception (expected)
160-
ParentIterator... exception (expected)
161-
LimitIterator... exception (expected)
162-
CachingIterator... exception (expected)
163-
RecursiveCachingIterator... exception (expected)
164-
NoRewindIterator... exception (expected)
165-
RegexIterator... exception (expected)
166-
RecursiveRegexIterator... exception (expected)
167-
GlobIterator... exception (expected)
168-
SplFileObject... exception (expected)
169-
SplTempFileObject... exception (expected)
170-
AppendIterator... exception (expected)
171-
InfiniteIterator... exception (expected)
157+
IteratorIterator... Error (expected)
158+
FilterIterator... Error (expected)
159+
RecursiveFilterIterator... Error (expected)
160+
ParentIterator... Error (expected)
161+
LimitIterator... Error (expected)
162+
CachingIterator... Error (expected)
163+
RecursiveCachingIterator... Error (expected)
164+
NoRewindIterator... Error (expected)
165+
RegexIterator... Error (expected)
166+
RecursiveRegexIterator... Error (expected)
167+
GlobIterator... Error (expected)
168+
SplFileObject... Error (expected)
169+
SplTempFileObject... Error (expected)
170+
AppendIterator... Error (expected)
171+
InfiniteIterator... Error (expected)

ext/spl/tests/bug55701.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function testBaseClass($f) {
1515
} catch (RuntimeException $e) {
1616
// Throwing a RuntimeException is the correct behaviour for some methods
1717
echo "ran normally (expected)\n";
18-
} catch (LogicException $e) {
18+
} catch (\Error $e) {
1919
// Throwing a LogicException is not correct
2020
echo "threw LogicException (unexpected)\n";
2121
}
@@ -27,8 +27,8 @@ function testChildClass($f) {
2727
try {
2828
$f();
2929
echo "didn't throw (unexpected)\n";
30-
} catch (LogicException $e) {
31-
echo "threw LogicException (expected)\n";
30+
} catch (\Error $e) {
31+
echo "threw Error (expected)\n";
3232
} catch (Exception $e) {
3333
echo "threw other exception (unexpected)\n";
3434
}
@@ -330,6 +330,6 @@ non-empty GlobIterator... ran normally (expected)
330330
======================= test there are no regressions =======================
331331
SplFileObject existent file... ran normally (expected)
332332
SplFileObject non-existent file... ran normally (expected)
333-
extends GlobIterator... threw LogicException (expected)
334-
extends SplFileObject... threw LogicException (expected)
335-
extends SplTempFileObject... threw LogicException (expected)
333+
extends GlobIterator... threw Error (expected)
334+
extends SplFileObject... threw Error (expected)
335+
extends SplTempFileObject... threw Error (expected)

ext/spl/tests/bug79710.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Run::main();
3232

3333
?>
3434
--EXPECTF--
35-
Fatal error: Uncaught RuntimeException: Object not initialized in %s:%d
35+
Fatal error: Uncaught Error: Object not initialized in %s:%d
3636
Stack trace:
3737
#0 %s(%d): SplFileObject->flock(2)
3838
#1 [internal function]: Target->__destruct()

ext/spl/tests/iterator_031.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ try
5656
{
5757
$ap->append($it);
5858
}
59-
catch(LogicException $e)
59+
catch(\Error $e)
6060
{
6161
echo $e->getMessage() . "\n";
6262
}

0 commit comments

Comments
 (0)