- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
是否可以覆盖已经设置的 register_shutdown_function
堆栈?像这样的东西:
function f1(){
echo "f1";
}
function f2(){
echo "f2";
}
register_shutdown_function("f1");
echo "actions here";
register_shutdown_function("f2");
call_to_undefined_function(); // to "produce" the error
在这种情况下,我希望脚本只调用 f2()
。这可能吗?
最佳答案
你不能直接做,但总有一个解决方法:
$first = register_cancellable_shutdown_function(function () {
echo "This function is never called\n";
});
$second = register_cancellable_shutdown_function(function () {
echo "This function is going to be called\n";
});
cancel_shutdown_function($first);
输出:
$ php test.php
This function is going to be called
The code :
function register_cancellable_shutdown_function($callback)
{
return new cancellable_shutdown_function_envelope($callback);
}
function cancel_shutdown_function($envelope)
{
$envelope->cancel();
}
final class cancellable_shutdown_function_envelope
{
private $callback;
public function __construct($callback)
{
$this->callback = $callback;
register_shutdown_function(function () {
$this->callback && call_user_func($this->callback);
});
}
public function cancel()
{
$this->callback = false;
}
}
关于php - register_shutdown_function 覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9431843/
这是我正在测试以处理错误的原始代码的片段。 第一种方法是拨打 fatalErrorHandler() ,但第二种方法不是调用 fatalErrorHandler() .可能是什么原因? 第一 out
当脚本出现 fatal error 时,我做了一个自定义重定向功能: 这在所有页面之前包含的前置脚本上调用: register_shutdown_function("shutdownHandler")
我有一个 PHP 类,可以动态创建 PNG 图像并将其发送到浏览器。 PHP 手册说我需要确保最后调用 imagedestroy 函数来释放内存。现在,如果我不使用类,我会有这样的代码: functi
我正在尝试用自定义函数替换内置的 php shutdown_function。 它工作得很好,但是,它仍然在我的新错误消息上方输出原始错误(内置错误)。 有什么想法吗? 最佳答案 正如评论中已经
是否可以覆盖已经设置的 register_shutdown_function 堆栈?像这样的东西: function f1(){ echo "f1"; } function f2(){
我目前出于多种目的使用 register_shutdown_function()。一种用途是处理 fatal error ,另一种用途是记录执行期间使用的资源,如时间、内存使用情况等。 目前我注册了两
我正在尝试使用一个关闭函数,该函数使用注册后动态更改的值。我的理解是,通过引用传递变量将允许代码后面部分的更改影响关闭调用。下面的代码证明情况并非如此: 我是不是误解了应该怎么做?将引用传递转换为值
我是 php 新手。我开始了解 php 中的 register_shutdown_function()。我在 php.net 手册中读到了这个函数,当脚本完成执行时这个函数调用。但是我有一个问题 如果
当从命令行(通过 Ctrl+c)或使用 kill 命令终止 cron 进程时,是否可以调用函数? 我已经尝试过register_shutdown_function(),但它似乎并没有在脚本被杀死时被调
通过 register_shutdown_function 方法,可以让我们设置一个当执行关闭时可以被调用的另一个函数。 也就是说,当我们的脚本执行完成或者意外死掉导致 php 执行即将关闭时,我
我试图捕捉 Zend Framework 应用程序中发生的 fatal error 。我试图从 Bootstrap 中调用 register_shutdown_function: protected
根据手册http://php.net/manual/en/function.register-shutdown-function.php ,register_shutdown_function() 实
根据手册http://php.net/manual/en/function.register-shutdown-function.php ,register_shutdown_function() 实
我正在尝试找到一种干净的方法来处理致命和严重错误(即没有输出缓冲),并且我读到在 register_shutdown_function 中使用 HTTP header 是不可能的。 问题是,当发生严重
我想弄清楚为什么php需要1整秒钟来执行register_shutdown_function。如果有办法克服的话。 "; } register_shutdown_function('shutdown'
我有方法,在这个方法中可能会发生 fatal error ,为了捕获这个错误我做了这个 class a { function shutDownFunction() { $err
如果我的脚本在 register_shutdown_function() 中被 die() 取消了,我能以某种方式检查吗? ? 像这样: register_shutdown_function('shu
我正在尝试使用 register_shutdown_function 来“捕获”PHP fatal error ,以便我可以返回一个干净的错误消息。 在一个简单的 PHP 文件中,以下两个测试用例都得
如果我在同一个脚本中定义了以下内容: register_shutdown_function('handlerOne'); set_error_handler('handlerTwo'); 是否有任何错
这个问题不太可能帮助任何 future 的访问者;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况有关,这些情况并不普遍适用于互联网的全局受众。为了帮助使这个问题更广泛地适用,visit
我是一名优秀的程序员,十分优秀!