gpt4 book ai didi

php - set_exception_handler()期望参数(exception_handler)是有效的回调

转载 作者:行者123 更新时间:2023-12-03 07:57:13 25 4
gpt4 key购买 nike

我有以下代码:

namespace Google\Ads\GoogleAds\Examples\BasicOperations;

set_exception_handler('exception_handler');


function exception_handler($exception) {
echo "Uncaught exception: " , $exception->getMessage(), "\n";
}

并得到以下错误(PHP 7.3):

Warning: set_exception_handler() expects the argument (exception_handler) to be a valid callback



似乎必须使用命名空间来引用异常处理程序功能-例如set_error_handler(“MyNamespace \ my_error_handler”);。 -但我没有找到可以正常工作的示例。

最佳答案

这有效:

<?php

namespace Google\Ads\GoogleAds\Examples\BasicOperations;

set_exception_handler('Google\Ads\GoogleAds\Examples\BasicOperations\exception_handler');

throw new \Exception('test');

function exception_handler($exception) {
echo "Uncaught exception: " , $exception->getMessage(), "\n";
}

https://3v4l.org/bbmL1

关于php - set_exception_handler()期望参数(exception_handler)是有效的回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58121265/

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