时间:2021-07-01 10:21:17 帮助过:4人阅读
<?php
declare(strict_types=1);
function foo(string $arg){
return 'test' . $arg;;
}
function testArithmeticError(){
try {
$value = 1 << -1;
} catch (ArithmeticError $e) {
echo 'show ArithmeticError:';
echo $e->getMessage();
}
}
function testAssertionError(){
ini_set('zend.assertions', 1);
ini_set('assert.exception', 1);
try {
assert(1>2);
} catch (AssertionError $e) {
echo 'show AssertionError:';
echo $e->getMessage();
}
}
function testParseError(){
try {
eval('asset(1>2)');
} catch (ParseError $e) {
echo 'show ParseError:';
echo $e->getMessage();
}
}
function testTypeError(){
try {
foo(123);
} catch (TypeError $e) {
echo 'show TypeError:';
echo $e->getMessage();
}
}
function testpisionByZeroError(){
try{
1%0;
}catch(pisionByZeroError $e){
echo 'show pisionByZeroError:';
echo $e->getMessage();
}
}
function testArgumentCountError(){
try{
foo();
}catch(ArgumentCountError $e){
echo 'show ArgumentCountError:';
echo $e->getMessage();
}
}
//foo("ArithmeticError")();
//foo("AssertionError")();
//foo("ParseError")();
//foo("TypeError")();
//foo("pisionByZeroError")();
//foo("ArgumentCountError")();
?>相关推荐:
php中的错误级别,php错误级别_PHP教程
以上就是PHP中定义的一些内置错误的详细内容,更多请关注Gxl网其它相关文章!