PHP code example of wikimedia / scoped-callback

1. Go to this page and download the library: Download wikimedia/scoped-callback library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wikimedia / scoped-callback example snippets


use Wikimedia\ScopedCallback;
$sc = new ScopedCallback( [ $this, 'teardown' ] );
// Even if this throws an exception, the callback will run
// or it'll run at the end of the function
$this->fooBar();
// If you want to manually call the callback
ScopedCallback::consume( $sc );
// or
unset( $sc );
// If you want to prevent it from being called
ScopedCallback::cancel( $sc );