summaryrefslogtreecommitdiff
path: root/ext/spl
diff options
context:
space:
mode:
authorNikita Popov <nikic@php.net>2015-04-02 18:52:32 +0200
committerNikita Popov <nikic@php.net>2015-04-06 11:27:34 +0200
commit122d759618a42bff105971b923fbbb5be02e34b9 (patch)
treefd4487414ffa3f120c77b19b9eb7dc409659c57e /ext/spl
parent884b0365dbe718f667d048dbc3d1cd9d9f12ab84 (diff)
downloadphp-git-122d759618a42bff105971b923fbbb5be02e34b9.tar.gz
Always throw TypeException on throwing zpp failures
Introduces a ZEND_PARSE_PARAMS_THROW flag for zpp, which forces to report FAILURE errors using a TypeException instead of a Warning, like it would happen in strict mode. Adds a zend_parse_parameters_throw() convenience function, which invokes zpp with this flag. Converts all cases I could identify, where we currently have throwing zpp usage in constructors and replaces them with this API. Error handling is still replaced to EH_THROW in some cases to handle other, domain-specific errors in constructors.
Diffstat (limited to 'ext/spl')
-rw-r--r--ext/spl/spl_array.c13
-rw-r--r--ext/spl/spl_directory.c27
-rw-r--r--ext/spl/spl_fixedarray.c9
-rw-r--r--ext/spl/spl_iterators.c37
-rw-r--r--ext/spl/spl_observer.c7
-rw-r--r--ext/spl/tests/CallbackFilterIteratorTest-002.phpt10
-rw-r--r--ext/spl/tests/SplFixedArray__construct_param_array.phpt5
-rw-r--r--ext/spl/tests/SplFixedArray__construct_param_string.phpt3
-rw-r--r--ext/spl/tests/SplFixedArray_construct_param_SplFixedArray.phpt3
-rw-r--r--ext/spl/tests/SplTempFileObject_constructor_error.phpt12
-rw-r--r--ext/spl/tests/arrayObject___construct_error1.phpt4
-rw-r--r--ext/spl/tests/arrayObject___construct_error2.phpt4
-rw-r--r--ext/spl/tests/arrayObject_setIteratorClass_error1.phpt4
-rw-r--r--ext/spl/tests/bug54292.phpt2
-rw-r--r--ext/spl/tests/fixedarray_005.phpt24
-rw-r--r--ext/spl/tests/fixedarray_009.phpt3
-rw-r--r--ext/spl/tests/fixedarray_015.phpt3
-rw-r--r--ext/spl/tests/iterator_056.phpt59
-rw-r--r--ext/spl/tests/iterator_059.phpt17
-rw-r--r--ext/spl/tests/iterator_060.phpt17
-rw-r--r--ext/spl/tests/iterator_061.phpt17
-rw-r--r--ext/spl/tests/iterator_063.phpt17
-rw-r--r--ext/spl/tests/iterator_064.phpt15
-rw-r--r--ext/spl/tests/iterator_065.phpt15
-rw-r--r--ext/spl/tests/iterator_066.phpt15
-rw-r--r--ext/spl/tests/recursive_tree_iterator_003.phpt10
-rw-r--r--ext/spl/tests/spl_iterator_iterator_constructor.phpt20
27 files changed, 130 insertions, 242 deletions
diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c
index 5e62bad6e4..a919d4bb5e 100644
--- a/ext/spl/spl_array.c
+++ b/ext/spl/spl_array.c
@@ -1220,21 +1220,17 @@ SPL_METHOD(Array, __construct)
zval *array;
zend_long ar_flags = 0;
zend_class_entry *ce_get_iterator = spl_ce_Iterator;
- zend_error_handling error_handling;
if (ZEND_NUM_ARGS() == 0) {
return; /* nothing to do */
}
- zend_replace_error_handling(EH_THROW, spl_ce_InvalidArgumentException, &error_handling);
-
- intern = Z_SPLARRAY_P(object);
-
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|lC", &array, &ar_flags, &ce_get_iterator) == FAILURE) {
- zend_restore_error_handling(&error_handling);
+ if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "z|lC", &array, &ar_flags, &ce_get_iterator) == FAILURE) {
return;
}
+ intern = Z_SPLARRAY_P(object);
+
if (ZEND_NUM_ARGS() > 2) {
intern->ce_get_iterator = ce_get_iterator;
}
@@ -1242,9 +1238,6 @@ SPL_METHOD(Array, __construct)
ar_flags &= ~SPL_ARRAY_INT_MASK;
spl_array_set_array(object, intern, array, ar_flags, ZEND_NUM_ARGS() == 1);
-
- zend_restore_error_handling(&error_handling);
-
}
/* }}} */
diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c
index b91e8b0558..3e250b1acc 100644
--- a/ext/spl/spl_directory.c
+++ b/ext/spl/spl_directory.c
@@ -1102,11 +1102,7 @@ SPL_METHOD(DirectoryIterator, isDot)
/* {{{ proto void SplFileInfo::__construct(string file_name)
Cronstructs a new SplFileInfo from a path. */
-/* zend_replace_error_handling() is used to throw exceptions in case
- the constructor fails. Here we use this to ensure the object
- has a valid directory resource.
-
- When the constructor gets called the object is already created
+/* When the constructor gets called the object is already created
by the engine, so we must only call 'additional' initializations.
*/
SPL_METHOD(SplFileInfo, __construct)
@@ -1114,12 +1110,8 @@ SPL_METHOD(SplFileInfo, __construct)
spl_filesystem_object *intern;
char *path;
size_t len;
- zend_error_handling error_handling;
-
- zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling);
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &path, &len) == FAILURE) {
- zend_restore_error_handling(&error_handling);
+ if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &path, &len) == FAILURE) {
return;
}
@@ -1127,8 +1119,6 @@ SPL_METHOD(SplFileInfo, __construct)
spl_filesystem_info_set_filename(intern, path, len, 1);
- zend_restore_error_handling(&error_handling);
-
/* intern->type = SPL_FS_INFO; already set */
}
/* }}} */
@@ -2272,18 +2262,15 @@ SPL_METHOD(SplFileObject, __construct)
size_t tmp_path_len;
zend_error_handling error_handling;
- zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling);
-
intern->u.file.open_mode = NULL;
intern->u.file.open_mode_len = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|sbr!",
+ if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "p|sbr!",
&intern->file_name, &intern->file_name_len,
&intern->u.file.open_mode, &intern->u.file.open_mode_len,
&use_include_path, &intern->u.file.zcontext) == FAILURE) {
intern->u.file.open_mode = NULL;
intern->file_name = NULL;
- zend_restore_error_handling(&error_handling);
return;
}
@@ -2292,6 +2279,8 @@ SPL_METHOD(SplFileObject, __construct)
intern->u.file.open_mode_len = 1;
}
+ zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling);
+
if (spl_filesystem_file_open(intern, use_include_path, 0) == SUCCESS) {
tmp_path_len = strlen(intern->u.file.stream->orig_path);
@@ -2331,10 +2320,7 @@ SPL_METHOD(SplTempFileObject, __construct)
spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(getThis());
zend_error_handling error_handling;
- zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling);
-
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &max_memory) == FAILURE) {
- zend_restore_error_handling(&error_handling);
+ if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "|l", &max_memory) == FAILURE) {
return;
}
@@ -2351,6 +2337,7 @@ SPL_METHOD(SplTempFileObject, __construct)
intern->u.file.open_mode = "wb";
intern->u.file.open_mode_len = 1;
+ zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling);
if (spl_filesystem_file_open(intern, 0, 0) == SUCCESS) {
intern->_path_len = 0;
intern->_path = estrndup("", 0);
diff --git a/ext/spl/spl_fixedarray.c b/ext/spl/spl_fixedarray.c
index 9dbfa61344..48e9d2f85f 100644
--- a/ext/spl/spl_fixedarray.c
+++ b/ext/spl/spl_fixedarray.c
@@ -561,14 +561,7 @@ SPL_METHOD(SplFixedArray, __construct)
spl_fixedarray_object *intern;
zend_long size = 0;
- int rv;
- zend_error_handling zeh;
-
- zend_replace_error_handling(EH_THROW, spl_ce_InvalidArgumentException, &zeh TSRMLS_CC);
- rv = zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &size);
- zend_restore_error_handling(&zeh TSRMLS_CC);
-
- if (rv == FAILURE) {
+ if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "|l", &size) == FAILURE) {
return;
}
diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c
index 3ffb8f7bec..e2267cfdcd 100644
--- a/ext/spl/spl_iterators.c
+++ b/ext/spl/spl_iterators.c
@@ -1067,6 +1067,8 @@ static void spl_recursive_tree_iterator_get_entry(spl_recursive_it_object *objec
data = iterator->funcs->get_current_data(iterator);
+ /* Replace exception handling so the catchable fatal error that is thrown when a class
+ * without __toString is converted to string is converted into an exception. */
zend_replace_error_handling(EH_THROW, spl_ce_UnexpectedValueException, &error_handling);
if (data) {
RETVAL_ZVAL(data, 1, 0);
@@ -1459,25 +1461,20 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
return NULL;
}
- zend_replace_error_handling(EH_THROW, spl_ce_InvalidArgumentException, &error_handling);
-
intern->dit_type = dit_type;
switch (dit_type) {
case DIT_LimitIterator: {
intern->u.limit.offset = 0; /* start at beginning */
intern->u.limit.count = -1; /* get all */
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|ll", &zobject, ce_inner, &intern->u.limit.offset, &intern->u.limit.count) == FAILURE) {
- zend_restore_error_handling(&error_handling);
+ if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "O|ll", &zobject, ce_inner, &intern->u.limit.offset, &intern->u.limit.count) == FAILURE) {
return NULL;
}
if (intern->u.limit.offset < 0) {
zend_throw_exception(spl_ce_OutOfRangeException, "Parameter offset must be >= 0", 0);
- zend_restore_error_handling(&error_handling);
return NULL;
}
if (intern->u.limit.count < 0 && intern->u.limit.count != -1) {
zend_throw_exception(spl_ce_OutOfRangeException, "Parameter count must either be -1 or a value greater than or equal 0", 0);
- zend_restore_error_handling(&error_handling);
return NULL;
}
break;
@@ -1485,13 +1482,11 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
case DIT_CachingIterator:
case DIT_RecursiveCachingIterator: {
zend_long flags = CIT_CALL_TOSTRING;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|l", &zobject, ce_inner, &flags) == FAILURE) {
- zend_restore_error_handling(&error_handling);
+ if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "O|l", &zobject, ce_inner, &flags) == FAILURE) {
return NULL;
}
if (spl_cit_check_flags(flags) != SUCCESS) {
zend_throw_exception(spl_ce_InvalidArgumentException, "Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER", 0);
- zend_restore_error_handling(&error_handling);
return NULL;
}
intern->u.caching.flags |= flags & CIT_PUBLIC;
@@ -1502,8 +1497,7 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
zend_class_entry *ce_cast;
zend_string *class_name;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|S", &zobject, ce_inner, &class_name) == FAILURE) {
- zend_restore_error_handling(&error_handling);
+ if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "O|S", &zobject, ce_inner, &class_name) == FAILURE) {
return NULL;
}
ce = Z_OBJCE_P(zobject);
@@ -1514,7 +1508,6 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
|| !ce_cast->get_iterator
) {
zend_throw_exception(spl_ce_LogicException, "Class to downcast to not found or not base class or does not implement Traversable", 0);
- zend_restore_error_handling(&error_handling);
return NULL;
}
ce = ce_cast;
@@ -1523,12 +1516,10 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
zend_call_method_with_0_params(zobject, ce, &ce->iterator_funcs.zf_new_iterator, "getiterator", &retval);
if (EG(exception)) {
zval_ptr_dtor(&retval);
- zend_restore_error_handling(&error_handling);
return NULL;
}
if (Z_TYPE(retval) != IS_OBJECT || !instanceof_function(Z_OBJCE(retval), zend_ce_traversable)) {
zend_throw_exception_ex(spl_ce_LogicException, 0, "%s::getIterator() must return an object that implements Traversable", ce->name->val);
- zend_restore_error_handling(&error_handling);
return NULL;
}
zobject = &retval;
@@ -1539,6 +1530,7 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
break;
}
case DIT_AppendIterator:
+ zend_replace_error_handling(EH_THROW, spl_ce_InvalidArgumentException, &error_handling);
spl_instantiate(spl_ce_ArrayIterator, &intern->u.append.zarrayit);
zend_call_method_with_0_params(&intern->u.append.zarrayit, spl_ce_ArrayIterator, &spl_ce_ArrayIterator->constructor, "__construct", NULL);
intern->u.append.iterator = spl_ce_ArrayIterator->get_iterator(spl_ce_ArrayIterator, &intern->u.append.zarrayit, 0);
@@ -1553,21 +1545,22 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
intern->u.regex.use_flags = ZEND_NUM_ARGS() >= 5;
intern->u.regex.flags = 0;
intern->u.regex.preg_flags = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "OS|lll", &zobject, ce_inner, &regex, &mode, &intern->u.regex.flags, &intern->u.regex.preg_flags) == FAILURE) {
- zend_restore_error_handling(&error_handling);
+ if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "OS|lll", &zobject, ce_inner, &regex, &mode, &intern->u.regex.flags, &intern->u.regex.preg_flags) == FAILURE) {
return NULL;
}
if (mode < 0 || mode >= REGIT_MODE_MAX) {
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Illegal mode %pd", mode);
- zend_restore_error_handling(&error_handling);
return NULL;
}
intern->u.regex.mode = mode;
intern->u.regex.regex = zend_string_copy(regex);
+
+ zend_replace_error_handling(EH_THROW, spl_ce_InvalidArgumentException, &error_handling);
intern->u.regex.pce = pcre_get_compiled_regex_cache(regex);
+ zend_restore_error_handling(&error_handling);
+
if (intern->u.regex.pce == NULL) {
/* pcre_get_compiled_regex_cache has already sent error */
- zend_restore_error_handling(&error_handling);
return NULL;
}
intern->u.regex.pce->refcount++;
@@ -1578,8 +1571,7 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
case DIT_RecursiveCallbackFilterIterator: {
_spl_cbfilter_it_intern *cfi = emalloc(sizeof(*cfi));
cfi->fci.object = NULL;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "Of", &zobject, ce_inner, &cfi->fci, &cfi->fcc) == FAILURE) {
- zend_restore_error_handling(&error_handling);
+ if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "Of", &zobject, ce_inner, &cfi->fci, &cfi->fcc) == FAILURE) {
efree(cfi);
return NULL;
}
@@ -1592,15 +1584,12 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
break;
}
default:
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &zobject, ce_inner) == FAILURE) {
- zend_restore_error_handling(&error_handling);
+ if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "O", &zobject, ce_inner) == FAILURE) {
return NULL;
}
break;
}
- zend_restore_error_handling(&error_handling);
-
if (inc_refcount) {
ZVAL_COPY(&intern->inner.zobject, zobject);
} else {
diff --git a/ext/spl/spl_observer.c b/ext/spl/spl_observer.c
index 619ed3883a..76933a8228 100644
--- a/ext/spl/spl_observer.c
+++ b/ext/spl/spl_observer.c
@@ -976,18 +976,13 @@ SPL_METHOD(MultipleIterator, __construct)
{
spl_SplObjectStorage *intern;
zend_long flags = MIT_NEED_ALL|MIT_KEYS_NUMERIC;
- zend_error_handling error_handling;
- zend_replace_error_handling(EH_THROW, spl_ce_InvalidArgumentException, &error_handling);
-
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &flags) == FAILURE) {
- zend_restore_error_handling(&error_handling);
+ if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "|l", &flags) == FAILURE) {
return;
}
intern = Z_SPLOBJSTORAGE_P(getThis());
intern->flags = flags;
- zend_restore_error_handling(&error_handling);
}
/* }}} */
diff --git a/ext/spl/tests/CallbackFilterIteratorTest-002.phpt b/ext/spl/tests/CallbackFilterIteratorTest-002.phpt
index bc4fd14647..1f71d3032a 100644
--- a/ext/spl/tests/CallbackFilterIteratorTest-002.phpt
+++ b/ext/spl/tests/CallbackFilterIteratorTest-002.phpt
@@ -10,27 +10,25 @@ set_error_handler(function($errno, $errstr){
try {
new CallbackFilterIterator();
-} catch(InvalidArgumentException $e) {
+} catch (TypeException $e) {
echo $e->getMessage() . "\n";
}
try {
new CallbackFilterIterator(null);
-} catch(InvalidArgumentException $e) {
- echo $e->getMessage() . "\n";
-} catch(EngineException $e) {
+} catch (TypeException $e) {
echo $e->getMessage() . "\n";
}
try {
new CallbackFilterIterator(new ArrayIterator(array()), null);
-} catch(InvalidArgumentException $e) {
+} catch (TypeException $e) {
echo $e->getMessage() . "\n";
}
try {
new CallbackFilterIterator(new ArrayIterator(array()), array());
-} catch(InvalidArgumentException $e) {
+} catch (TypeException $e) {
echo $e->getMessage() . "\n";
}
diff --git a/ext/spl/tests/SplFixedArray__construct_param_array.phpt b/ext/spl/tests/SplFixedArray__construct_param_array.phpt
index aa5933ebdb..e1515c4039 100644
--- a/ext/spl/tests/SplFixedArray__construct_param_array.phpt
+++ b/ext/spl/tests/SplFixedArray__construct_param_array.phpt
@@ -7,11 +7,10 @@ PHPNW Test Fest 2009 - Jordan Hatch
try {
$array = new SplFixedArray( array("string", 1) );
-}
-catch(InvalidArgumentException $iae) {
+} catch (TypeException $iae) {
echo "Ok - ".$iae->getMessage().PHP_EOL;
}
?>
--EXPECTF--
-Ok - SplFixedArray::__construct() expects parameter 1 to be integer, array given \ No newline at end of file
+Ok - SplFixedArray::__construct() expects parameter 1 to be integer, array given
diff --git a/ext/spl/tests/SplFixedArray__construct_param_string.phpt b/ext/spl/tests/SplFixedArray__construct_param_string.phpt
index 411d7402df..66c7fe6a59 100644
--- a/ext/spl/tests/SplFixedArray__construct_param_string.phpt
+++ b/ext/spl/tests/SplFixedArray__construct_param_string.phpt
@@ -6,8 +6,7 @@ PHPNW Test Fest 2009 - Jordan Hatch
<?php
try {
$array = new SplFixedArray( "string" );
-}
-catch(InvalidArgumentException $iae) {
+} catch (TypeException $iae) {
echo "Ok - ".$iae->getMessage().PHP_EOL;
}
diff --git a/ext/spl/tests/SplFixedArray_construct_param_SplFixedArray.phpt b/ext/spl/tests/SplFixedArray_construct_param_SplFixedArray.phpt
index 10d4c64a0c..20f4e7970c 100644
--- a/ext/spl/tests/SplFixedArray_construct_param_SplFixedArray.phpt
+++ b/ext/spl/tests/SplFixedArray_construct_param_SplFixedArray.phpt
@@ -6,8 +6,7 @@ Philip Norton philipnorton42@gmail.com
<?php
try {
$array = new SplFixedArray(new SplFixedArray(3));
-}
-catch(InvalidArgumentException $iae) {
+} catch (TypeException $iae) {
echo "Ok - ".$iae->getMessage().PHP_EOL;
}
diff --git a/ext/spl/tests/SplTempFileObject_constructor_error.phpt b/ext/spl/tests/SplTempFileObject_constructor_error.phpt
index a6c71717b5..8eb306689d 100644
--- a/ext/spl/tests/SplTempFileObject_constructor_error.phpt
+++ b/ext/spl/tests/SplTempFileObject_constructor_error.phpt
@@ -2,11 +2,11 @@
SPL SplTempFileObject constructor sets correct defaults when pass 0 arguments
--FILE--
<?php
-new SplTempFileObject('invalid');
+try {
+ new SplTempFileObject('invalid');
+} catch (TypeException $e) {
+ echo $e->getMessage(), "\n";
+}
?>
--EXPECTF--
-Fatal error: Uncaught exception 'RuntimeException' with message 'SplTempFileObject::__construct() expects parameter 1 to be integer, string given' in %s
-Stack trace:
-#0 %s: SplTempFileObject->__construct('invalid')
-#1 {main}
- thrown in %s
+SplTempFileObject::__construct() expects parameter 1 to be integer, string given
diff --git a/ext/spl/tests/arrayObject___construct_error1.phpt b/ext/spl/tests/arrayObject___construct_error1.phpt
index 21c312d2d0..cff0dd048d 100644
--- a/ext/spl/tests/arrayObject___construct_error1.phpt
+++ b/ext/spl/tests/arrayObject___construct_error1.phpt
@@ -7,14 +7,14 @@ $a = new stdClass;
$a->p = 1;
try {
var_dump(new ArrayObject($a, 0, "Exception"));
-} catch (InvalidArgumentException $e) {
+} catch (TypeException $e) {
echo $e->getMessage() . "(" . $e->getLine() . ")\n";
}
echo "Non-existent class:\n";
try {
var_dump(new ArrayObject(new stdClass, 0, "nonExistentClassName"));
-} catch (InvalidArgumentException $e) {
+} catch (TypeException $e) {
echo $e->getMessage() . "(" . $e->getLine() . ")\n";
}
?>
diff --git a/ext/spl/tests/arrayObject___construct_error2.phpt b/ext/spl/tests/arrayObject___construct_error2.phpt
index 850a2cb3fc..d075516725 100644
--- a/ext/spl/tests/arrayObject___construct_error2.phpt
+++ b/ext/spl/tests/arrayObject___construct_error2.phpt
@@ -13,10 +13,10 @@ Class C implements Iterator {
try {
var_dump(new ArrayObject(new stdClass, 0, "C", "extra"));
-} catch (InvalidArgumentException $e) {
+} catch (TypeException $e) {
echo $e->getMessage() . "(" . $e->getLine() . ")\n";
}
?>
--EXPECTF--
Too many arguments:
-ArrayObject::__construct() expects at most 3 parameters, 4 given(12) \ No newline at end of file
+ArrayObject::__construct() expects at most 3 parameters, 4 given(12)
diff --git a/ext/spl/tests/arrayObject_setIteratorClass_error1.phpt b/ext/spl/tests/arrayObject_setIteratorClass_error1.phpt
index 4715eea986..b4c3756cb5 100644
--- a/ext/spl/tests/arrayObject_setIteratorClass_error1.phpt
+++ b/ext/spl/tests/arrayObject_setIteratorClass_error1.phpt
@@ -28,7 +28,7 @@ try {
foreach($ao as $key=>$value) {
echo " $key=>$value\n";
}
-} catch (Exception $e) {
+} catch (TypeException $e) {
var_dump($e->getMessage());
}
@@ -37,7 +37,7 @@ try {
foreach($ao as $key=>$value) {
echo " $key=>$value\n";
}
-} catch (Exception $e) {
+} catch (TypeException $e) {
var_dump($e->getMessage());
}
diff --git a/ext/spl/tests/bug54292.phpt b/ext/spl/tests/bug54292.phpt
index d9175f7e6f..44d12ee242 100644
--- a/ext/spl/tests/bug54292.phpt
+++ b/ext/spl/tests/bug54292.phpt
@@ -5,7 +5,7 @@ Bug #54292 (Wrong parameter causes crash in SplFileObject::__construct())
try {
new SplFileObject('foo', array());
-} catch (Exception $e) {
+} catch (TypeException $e) {
var_dump($e->getMessage());
}
diff --git a/ext/spl/tests/fixedarray_005.phpt b/ext/spl/tests/fixedarray_005.phpt
index 72970a9a1f..83727a23b9 100644
--- a/ext/spl/tests/fixedarray_005.phpt
+++ b/ext/spl/tests/fixedarray_005.phpt
@@ -1,18 +1,30 @@
--TEST--
-SPL: FixedArray: Trying to instantiate passing object to constructor parameter
+SPL: FixedArray: Invalid arguments
--FILE--
<?php
-$b = new stdClass;
-
try {
- $a = new SplFixedArray($b);
+ $a = new SplFixedArray(new stdClass);
+} catch (TypeException $iae) {
+ echo "Ok - ".$iae->getMessage().PHP_EOL;
}
-catch(InvalidArgumentException $iae) {
+
+try {
+ $a = new SplFixedArray('FOO');
+} catch (TypeException $iae) {
echo "Ok - ".$iae->getMessage().PHP_EOL;
}
+try {
+ $a = new SplFixedArray('');
+} catch (TypeException $iae) {
+ echo "Ok - ".$iae->getMessage().PHP_EOL;
+}
?>
---EXPECTF--
+===DONE===
+--EXPECT--
Ok - SplFixedArray::__construct() expects parameter 1 to be integer, object given
+Ok - SplFixedArray::__construct() expects parameter 1 to be integer, string given
+Ok - SplFixedArray::__construct() expects parameter 1 to be integer, string given
+===DONE===
diff --git a/ext/spl/tests/fixedarray_009.phpt b/ext/spl/tests/fixedarray_009.phpt
index d67c7ccb69..f255ed299a 100644
--- a/ext/spl/tests/fixedarray_009.phpt
+++ b/ext/spl/tests/fixedarray_009.phpt
@@ -5,8 +5,7 @@ SPL: FixedArray: Trying to instantiate passing string to construtor parameter
try {
$a = new SplFixedArray('FOO');
-}
-catch(InvalidArgumentException $iae) {
+} catch (TypeException $iae) {
echo "Ok - ".$iae->getMessage().PHP_EOL;
}
?>
diff --git a/ext/spl/tests/fixedarray_015.phpt b/ext/spl/tests/fixedarray_015.phpt
index f12d83bb39..d189d41da3 100644
--- a/ext/spl/tests/fixedarray_015.phpt
+++ b/ext/spl/tests/fixedarray_015.phpt
@@ -5,8 +5,7 @@ SPL: FixedArray: accessing uninitialized array
try {
$a = new SplFixedArray('');
-}
-catch(InvalidArgumentException $iae) {
+} catch (TypeException $iae) {
echo "Ok - ".$iae->getMessage().PHP_EOL;
}
diff --git a/ext/spl/tests/iterator_056.phpt b/ext/spl/tests/iterator_056.phpt
index 4b0e75a7d4..ee98263638 100644
--- a/ext/spl/tests/iterator_056.phpt
+++ b/ext/spl/tests/iterator_056.phpt
@@ -1,19 +1,64 @@
--TEST--
-SPL: FilterIterator::__construct(void)
+SPL: Calling __construct(void) on class extending SPL iterator
--CREDITS--
Sebastian Schürmann
--FILE--
<?php
+
class myFilterIterator extends FilterIterator {
- function accept() {
-
- }
+ function accept() { }
}
+
+class myCachingIterator extends CachingIterator { }
+
+class myRecursiveCachingIterator extends RecursiveCachingIterator { }
+
+class myParentIterator extends ParentIterator { }
+
+class myLimitIterator extends LimitIterator { }
+
+class myNoRewindIterator extends NoRewindIterator {}
+
try {
$it = new myFilterIterator();
-} catch (InvalidArgumentException $e) {
- echo 'InvalidArgumentException thrown';
+} catch (TypeException $e) {
+ echo $e->getMessage(), "\n";
}
+
+try {
+ $it = new myCachingIterator();
+} catch (TypeException $e) {
+ echo $e->getMessage(), "\n";
+}
+
+try {
+ $it = new myRecursiveCachingIterator();
+} catch (TypeException $e) {
+ echo $e->getMessage(), "\n";
+}
+
+try {
+ $it = new myParentIterator();
+} catch (TypeException $e) {
+ echo $e->getMessage(), "\n";
+}
+
+try {
+ $it = new myLimitIterator();
+} catch (TypeException $e) {
+ echo $e->getMessage(), "\n";
+}
+try {
+ $it = new myNoRewindIterator();
+} catch (TypeException $e) {
+ echo $e->getMessage(), "\n";
+}
+
?>
--EXPECT--
-InvalidArgumentException thrown
+FilterIterator::__construct() expects exactly 1 parameter, 0 given
+CachingIterator::__construct() expects at least 1 parameter, 0 given
+RecursiveCachingIterator::__construct() expects at least 1 parameter, 0 given
+ParentIterator::__construct() expects exactly 1 parameter, 0 given
+LimitIterator::__construct() expects at least 1 parameter, 0 given
+NoRewindIterator::__construct() expects exactly 1 parameter, 0 given
diff --git a/ext/spl/tests/iterator_059.phpt b/ext/spl/tests/iterator_059.phpt
deleted file mode 100644
index 8c579ae43a..0000000000
--- a/ext/spl/tests/iterator_059.phpt
+++ /dev/null
@@ -1,17 +0,0 @@
---TEST--
-SPL: CachingIterator::__construct(void)
---CREDITS--
-Sebastian Schürmann
---FILE--
-<?php
-class myCachingIterator extends CachingIterator {
-
-}
-try {
- $it = new myCachingIterator();
-} catch (InvalidArgumentException $e) {
- echo 'InvalidArgumentException thrown';
-}
-?>
---EXPECT--
-InvalidArgumentException thrown
diff --git a/ext/spl/tests/iterator_060.phpt b/ext/spl/tests/iterator_060.phpt
deleted file mode 100644
index 0c3b6c21d2..0000000000
--- a/ext/spl/tests/iterator_060.phpt
+++ /dev/null
@@ -1,17 +0,0 @@
---TEST--
-SPL: RecursiveCachingIterator::__construct(void)
---CREDITS--
-Sebastian Schürmann
---FILE--
-<?php
-class myRecursiveCachingIterator extends RecursiveCachingIterator {
-
-}
-try {
- $it = new myRecursiveCachingIterator();
-} catch (InvalidArgumentException $e) {
- echo 'InvalidArgumentException thrown';
-}
-?>
---EXPECT--
-InvalidArgumentException thrown
diff --git a/ext/spl/tests/iterator_061.phpt b/ext/spl/tests/iterator_061.phpt
deleted file mode 100644
index 472f8da196..0000000000
--- a/ext/spl/tests/iterator_061.phpt
+++ /dev/null
@@ -1,17 +0,0 @@
---TEST--
-SPL: ParentIterator::__construct(void)
---CREDITS--
-Sebastian Schürmann
---FILE--
-<?php
-class myParentIterator extends ParentIterator {
-
-}
-try {
- $it = new myParentIterator();
-} catch (InvalidArgumentException $e) {
- echo 'InvalidArgumentException thrown';
-}
-?>
---EXPECT--
-InvalidArgumentException thrown
diff --git a/ext/spl/tests/iterator_063.phpt b/ext/spl/tests/iterator_063.phpt
deleted file mode 100644
index 4d4112bac5..0000000000
--- a/ext/spl/tests/iterator_063.phpt
+++ /dev/null
@@ -1,17 +0,0 @@
---TEST--
-SPL: LimitIterator::__construct(void)
---CREDITS--
-Sebastian Schürmann
---FILE--
-<?php
-class myLimitIterator extends LimitIterator {
-
-}
-try {
- $it = new myLimitIterator();
-} catch (InvalidArgumentException $e) {
- echo 'InvalidArgumentException thrown';
-}
-?>
---EXPECT--
-InvalidArgumentException thrown
diff --git a/ext/spl/tests/iterator_064.phpt b/ext/spl/tests/iterator_064.phpt
deleted file mode 100644
index 6a62e6c9c5..0000000000
--- a/ext/spl/tests/iterator_064.phpt
+++ /dev/null
@@ -1,15 +0,0 @@
---TEST--
-SPL: CachingIterator::__construct(void)
---CREDITS--
-Sebastian Schürmann
---FILE--
-<?php
-class myCachingIterator extends CachingIterator {}
-try {
- $it = new myCachingIterator();
-} catch (InvalidArgumentException $e) {
- echo 'InvalidArgumentException thrown';
-}
-?>
---EXPECT--
-InvalidArgumentException thrown
diff --git a/ext/spl/tests/iterator_065.phpt b/ext/spl/tests/iterator_065.phpt
deleted file mode 100644
index 9ea2974cd4..0000000000
--- a/ext/spl/tests/iterator_065.phpt
+++ /dev/null
@@ -1,15 +0,0 @@
---TEST--
-SPL: RecursiveCachingIterator::__construct(void)
---CREDITS--
-Sebastian Schürmann
---FILE--
-<?php
-class myRecursiveCachingIterator extends RecursiveCachingIterator {}
-try {
- $it = new myRecursiveCachingIterator();
-} catch (InvalidArgumentException $e) {
- echo 'InvalidArgumentException thrown';
-}
-?>
---EXPECT--
-InvalidArgumentException thrown
diff --git a/ext/spl/tests/iterator_066.phpt b/ext/spl/tests/iterator_066.phpt
deleted file mode 100644
index 008c47ccc5..0000000000
--- a/ext/spl/tests/iterator_066.phpt
+++ /dev/null
@@ -1,15 +0,0 @@
---TEST--
-SPL: NoRewindIterator::__construct(void)
---CREDITS--
-Sebastian Schürmann
---FILE--
-<?php
-class myNoRewindIterator extends NoRewindIterator {}
-try {
- $it = new myNoRewindIterator();
-} catch (InvalidArgumentException $e) {
- echo 'InvalidArgumentException thrown';
-}
-?>
---EXPECT--
-InvalidArgumentException thrown
diff --git a/ext/spl/tests/recursive_tree_iterator_003.phpt b/ext/spl/tests/recursive_tree_iterator_003.phpt
index 83c8553942..4cc7000a19 100644
--- a/ext/spl/tests/recursive_tree_iterator_003.phpt
+++ b/ext/spl/tests/recursive_tree_iterator_003.phpt
@@ -1,16 +1,14 @@
--TEST--
SPL: RecursiveTreeIterator(non-traversable)
---INI--
-error_reporting=E_ALL&~E_NOTICE
--FILE--
<?php
try {
new RecursiveTreeIterator(new ArrayIterator(array()));
-} catch (InvalidArgumentException $e) {
- echo "InvalidArgumentException thrown\n";
+} catch (TypeException $e) {
+ echo $e->getMessage(), "\n";
}
?>
===DONE===
---EXPECTF--
-InvalidArgumentException thrown
+--EXPECT--
+RecursiveCachingIterator::__construct() expects parameter 1 to be RecursiveIterator, object given
===DONE===
diff --git a/ext/spl/tests/spl_iterator_iterator_constructor.phpt b/ext/spl/tests/spl_iterator_iterator_constructor.phpt
index d4fdb14c13..ec103f5c9c 100644
--- a/ext/spl/tests/spl_iterator_iterator_constructor.phpt
+++ b/ext/spl/tests/spl_iterator_iterator_constructor.phpt
@@ -6,23 +6,19 @@ TestFest London May 2009
--FILE--
<?php
- //I think this is testing line 1297 of spl_iterators.c
-
- $array = array(array(7,8,9),1,2,3,array(4,5,6));
+$array = array(array(7,8,9),1,2,3,array(4,5,6));
$arrayIterator = new ArrayIterator($array);
try {
-$test = new IteratorIterator($arrayIterator);
-
-$test = new IteratorIterator($arrayIterator, 1);
-$test = new IteratorIterator($arrayIterator, 1, 1);
-$test = new IteratorIterator($arrayIterator, 1, 1, 1);
-$test = new IteratorIterator($arrayIterator, 1, 1, 1, 1);
+ $test = new IteratorIterator($arrayIterator);
-} catch (InvalidArgumentException $e){
- print $e->getMessage() . "\n";
+ $test = new IteratorIterator($arrayIterator, 1);
+ $test = new IteratorIterator($arrayIterator, 1, 1);
+ $test = new IteratorIterator($arrayIterator, 1, 1, 1);
+ $test = new IteratorIterator($arrayIterator, 1, 1, 1, 1);
+} catch (TypeException $e){
+ echo $e->getMessage() . "\n";
}
-
?>
===DONE===
--EXPECTF--