gpt4 book ai didi

php - PHP 7.0.20:异常的代码为0

转载 作者:行者123 更新时间:2023-12-02 07:21:05 25 4
gpt4 key购买 nike

我收到错误代码为0的异常,但为什么不呢?异常的文本/消息是“在null上调用成员函数getId()”,但属性“代码”为0。为什么它为0而不是实数?所有其他异常均具有正确的错误代码。

是我的php.ini中的错误还是配置错误?

有人知道吗?

最佳答案

异常并不总是具有代码。如果未明确定义,则错误代码默认为0。请参阅http://www.php.net/manual/en/exception.construct.php-异常将默认为""消息,0代码和先前的NULL异常。

try {
throw new Exception('Hello!');
} catch(Exception $e) {
echo $e->getCode(); // prints 0
}

同样的事情,例如PHP错误:
try {
$foo = new stdClass;
$foo->fooBar();
} catch(Error $e) {
echo $e->getCode(); // prints 0 too
echo $e->getMessage(); // prints "Call to a member function fooBar() on null"
}

关于php - PHP 7.0.20:异常的代码为0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46226278/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com