Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass arguments to callable method specifically for register_shutdown_function?

I have method, in this method may be happened fatal error, for catching this error I make this

class a {


    function shutDownFunction() { 
        $error = error_get_last();
        if ($error['type'] == 1) {
            echo "this is fatal error";
        } 
    }


    function terribleFunction () {
        register_shutdown_function(array($this,'shutdownFunction'));


        // here is code, wich may causes fatal error

    }


}

Okay, this understand, but I need pass argument from terribleFunction to shutDownFunction. How to make this?

like image 563
Oto Shavadze Avatar asked Dec 04 '12 12:12

Oto Shavadze


1 Answers

First you need to specify that shutDownFunction should accept a parameter.

function shutDownFunction($var)

Then you can call register_shutdown_function as so

register_shutdown_function(array($this, 'shutdownFunction'), $myVar);

Documentation is here and there are examples in the comments.

like image 52
Rawkode Avatar answered Nov 14 '22 16:11

Rawkode