mirror of
https://github.com/php/php-src.git
synced 2026-03-26 09:12:14 +01:00
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.
57 lines
1.5 KiB
PHP
57 lines
1.5 KiB
PHP
--TEST--
|
|
SPL: ArrayObject with bad iterator class.
|
|
--FILE--
|
|
<?php
|
|
try {
|
|
$ao = new ArrayObject(array('a'=>1,'b'=>2,'c'=>3));
|
|
$ao->setIteratorClass("nonExistentClass");
|
|
foreach($ao as $key=>$value) {
|
|
echo " $key=>$value\n";
|
|
}
|
|
} catch (Exception $e) {
|
|
var_dump($e->getMessage());
|
|
}
|
|
|
|
try {
|
|
$ao = new ArrayObject(array('a'=>1,'b'=>2,'c'=>3));
|
|
$ao->setIteratorClass("stdClass");
|
|
foreach($ao as $key=>$value) {
|
|
echo " $key=>$value\n";
|
|
}
|
|
} catch (Exception $e) {
|
|
var_dump($e->getMessage());
|
|
}
|
|
|
|
|
|
try {
|
|
$ao = new ArrayObject(array('a'=>1,'b'=>2,'c'=>3), 0, "nonExistentClass");
|
|
foreach($ao as $key=>$value) {
|
|
echo " $key=>$value\n";
|
|
}
|
|
} catch (TypeException $e) {
|
|
var_dump($e->getMessage());
|
|
}
|
|
|
|
try {
|
|
$ao = new ArrayObject(array('a'=>1,'b'=>2,'c'=>3), 0, "stdClass");
|
|
foreach($ao as $key=>$value) {
|
|
echo " $key=>$value\n";
|
|
}
|
|
} catch (TypeException $e) {
|
|
var_dump($e->getMessage());
|
|
}
|
|
|
|
?>
|
|
--EXPECTF--
|
|
Warning: ArrayObject::setIteratorClass() expects parameter 1 to be a class name derived from Iterator, 'nonExistentClass' given in %s on line 4
|
|
a=>1
|
|
b=>2
|
|
c=>3
|
|
|
|
Warning: ArrayObject::setIteratorClass() expects parameter 1 to be a class name derived from Iterator, 'stdClass' given in %s on line 14
|
|
a=>1
|
|
b=>2
|
|
c=>3
|
|
string(113) "ArrayObject::__construct() expects parameter 3 to be a class name derived from Iterator, 'nonExistentClass' given"
|
|
string(105) "ArrayObject::__construct() expects parameter 3 to be a class name derived from Iterator, 'stdClass' given"
|