php - 为什么我的 'shutdown callback '在使用register_shutdown_function()时无效?

标签 php compiler-errors shutdown traits

警告:register_shutdown_function():无效的关机回调

trait ErrorTrait {

        public function shutDownFunction() { 
            $error = error_get_last();
                // fatal error, E_ERROR === 1
                if ($error['type'] === E_ERROR) { 
                    //do your stuff     

                    $messageStore="Using $this when not in object context";

                    if (strstr ( $error['message'],$messageStore))

                    {
                        echo "found it";

                    }

                } 
                }




        public function shutdown_function()
        {
        register_shutdown_function('shutDownFunction');
        } 

我在我的主类中使用这个特征并从中调用函数

    use ErrorTrait;

     public function test()
{   self::shutDownFunction();


    self::shutdown_function(); }

然后此时我在名为“run”的函数中调用测试中的函数

我所做的只是简单地调用函数。

      public function run()
        {
        self::test ();
          // Rest of code}

关于为什么这会导致问题的任何想法?

最佳答案

您正在将字符串而不是可调用对象传递到 register_shutdown_function。调用应该看起来像

register_shutdown_function([$this, 'shutDownFunction']);

关于php - 为什么我的 'shutdown callback '在使用register_shutdown_function()时无效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36881034/

相关文章:

c - shutdown() 和 close() 什么都不做

php - 如何关闭 xampp 中的通知报告?

php - Symfony2 - SonataAdmin - 空 admin_list block

c++ - Netbeans makefile : Trouble compiling . h 文件

compilation - linux内核编译: ERROR: "function" [path/to/module/module. ko]未定义

compiler-errors - 在Windows 10上构建OBS-Studio时发生编译时错误

python - 在 shutdown 命令中使用变量

php - 如何格式化带有前导零和千位逗号的数字?

php - 使表单 URL 提交看起来像路由而不是查询字符串

Tomcat 9 关闭在 Windows 和 Linux 上不起作用