PHP code example of slexx / callback

1. Go to this page and download the library: Download slexx/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/ */

    

slexx / callback example snippets


use Slexx\Callback\Callback;

$callback1 = new Callback('\NameSpace\ClassName::staticMethod');
$callback2 = new Callback('\NameSpace\ClassName->method');

use Slexx\Callback\Callback;

$callback1 = new Callback([$object, 'method']);
$callback2 = new Callback(function($name) {
    return 'Hello, ' . $name . '!';
});

use Slexx\Callback\Callback;

$callback = new Callback(function($name) {
    return 'Hello, ' . $name . '!';
});

echo $callback->invoke('Alex') . '<br>';
echo $callback->invokeArgs(['Alex']) . '<br>';
echo $callback('Alex');

$callback = new Callback(function($arg1, $arg2) {
    var_dump(func_get_args());
});
$callback->invokeArgs(['arg1', 2]);

$callback = new Callback(function($arg1, $arg2) {
    var_dump(func_get_args());
});
$callback->invoke('arg1', 2);

$callback = new Callback(function($arg1, $arg2) {
    var_dump(func_get_args());
});
$callback('arg1', 2);