Browse Source
Always throw TypeException on throwing zpp failures
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.pull/1215/merge
88 changed files with 424 additions and 640 deletions
-
4Zend/zend.c
-
2Zend/zend.h
-
44Zend/zend_API.c
-
2Zend/zend_API.h
-
40ext/date/php_date.c
-
15ext/date/tests/DateTimeZone_construct_error.phpt
-
2ext/date/tests/DateTimeZone_construct_variation1.phpt
-
14ext/date/tests/DateTime_construct_error.phpt
-
4ext/date/tests/DateTime_construct_variation1.phpt
-
2ext/date/tests/DateTime_construct_variation2.phpt
-
8ext/dom/attr.c
-
8ext/dom/cdatasection.c
-
8ext/dom/comment.c
-
8ext/dom/document.c
-
8ext/dom/documentfragment.c
-
8ext/dom/element.c
-
9ext/dom/entityreference.c
-
9ext/dom/processinginstruction.c
-
12ext/dom/tests/DOMAttr_construct_error_001.phpt
-
10ext/dom/tests/DOMCDATASection_construct_error_001.phpt
-
12ext/dom/tests/DOMComment_construct_error_001.phpt
-
12ext/dom/tests/DOMDocumentFragment_construct_error_001.phpt
-
8ext/dom/text.c
-
8ext/dom/xpath.c
-
14ext/fileinfo/fileinfo.c
-
14ext/fileinfo/tests/bug61173.phpt
-
14ext/fileinfo/tests/finfo_open_error.phpt
-
3ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp
-
13ext/intl/calendar/gregoriancalendar_methods.cpp
-
9ext/intl/collator/collator_create.c
-
11ext/intl/converter/converter.c
-
9ext/intl/dateformat/dateformat_create.cpp
-
9ext/intl/formatter/formatter_main.c
-
10ext/intl/intl_error.c
-
8ext/intl/intl_error.h
-
9ext/intl/msgformat/msgformat.c
-
9ext/intl/resourcebundle/resourcebundle_class.c
-
7ext/intl/spoofchecker/spoofchecker_create.c
-
6ext/intl/tests/breakiter___construct_error.phpt
-
17ext/intl/tests/formatter_fail.phpt
-
2ext/intl/tests/gregoriancalendar___construct_error.phpt
-
25ext/intl/tests/msgfmt_fail.phpt
-
25ext/intl/tests/msgfmt_fail2.phpt
-
6ext/pdo/pdo_dbh.c
-
2ext/pdo_mysql/tests/pdo_mysql___construct.phpt
-
2ext/pdo_mysql/tests/pdo_mysql___construct_options.phpt
-
21ext/phar/phar_object.c
-
2ext/phar/tests/badparameters.phpt
-
10ext/phar/tests/bug60261.phpt
-
15ext/phar/tests/pharfileinfo_construct.phpt
-
86ext/reflection/php_reflection.c
-
9ext/reflection/tests/ReflectionExtension_constructor_error.phpt
-
14ext/reflection/tests/ReflectionFunction_construct.001.phpt
-
6ext/reflection/tests/ReflectionMethod_006.phpt
-
6ext/reflection/tests/ReflectionMethod_constructor_error2.phpt
-
2ext/reflection/tests/ReflectionParameter_invalidMethodInConstructor.phpt
-
9ext/reflection/tests/ReflectionProperty_error.phpt
-
7ext/simplexml/simplexml.c
-
9ext/snmp/snmp.c
-
13ext/spl/spl_array.c
-
27ext/spl/spl_directory.c
-
9ext/spl/spl_fixedarray.c
-
37ext/spl/spl_iterators.c
-
7ext/spl/spl_observer.c
-
10ext/spl/tests/CallbackFilterIteratorTest-002.phpt
-
5ext/spl/tests/SplFixedArray__construct_param_array.phpt
-
3ext/spl/tests/SplFixedArray__construct_param_string.phpt
-
3ext/spl/tests/SplFixedArray_construct_param_SplFixedArray.phpt
-
12ext/spl/tests/SplTempFileObject_constructor_error.phpt
-
4ext/spl/tests/arrayObject___construct_error1.phpt
-
4ext/spl/tests/arrayObject___construct_error2.phpt
-
4ext/spl/tests/arrayObject_setIteratorClass_error1.phpt
-
2ext/spl/tests/bug54292.phpt
-
24ext/spl/tests/fixedarray_005.phpt
-
3ext/spl/tests/fixedarray_009.phpt
-
3ext/spl/tests/fixedarray_015.phpt
-
59ext/spl/tests/iterator_056.phpt
-
17ext/spl/tests/iterator_059.phpt
-
17ext/spl/tests/iterator_060.phpt
-
17ext/spl/tests/iterator_061.phpt
-
17ext/spl/tests/iterator_063.phpt
-
15ext/spl/tests/iterator_064.phpt
-
15ext/spl/tests/iterator_065.phpt
-
15ext/spl/tests/iterator_066.phpt
-
10ext/spl/tests/recursive_tree_iterator_003.phpt
-
20ext/spl/tests/spl_iterator_iterator_constructor.phpt
-
13ext/sqlite3/sqlite3.c
-
2ext/sqlite3/tests/sqlite3_02_open.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=== |
|||
@ -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 |
|||
@ -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 |
|||
@ -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 |
|||
@ -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 |
|||
@ -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 |
|||
@ -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 |
|||
@ -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 |
|||
@ -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 |
|||
@ -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=== |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue