Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my 'shutdown callback ' invalid when using register_shutdown_function()?

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?

like image 830
Flaco_Taco Avatar asked Apr 27 '16 05:04

Flaco_Taco


1 Answers

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

register_shutdown_function([$this, 'shutDownFunction']);
like image 108
Ruslan Osmanov Avatar answered Nov 02 '22 23:11

Ruslan Osmanov