Why is my 'shutdown callback ' invalid whe

2020-03-20 14:33发布

问题:

Warning: register_shutdown_function(): Invalid shutdown callback

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');
        } 

}

I use this trait in my main class and call the functions from it

    use ErrorTrait;

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


    self::shutdown_function(); }

And then at this point I call the function in test in a function called "run"

All I do is a simply call the function.

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

Any ideas as to why this is causing problems?

回答1:

You are passing a string instead of a callable into register_shutdown_function. The call should look like

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