PHP code example of txiki / callback

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

    

txiki / callback example snippets


$a = 'extra';
$cObject = new CallableObject(
	function($foo, $bar) use ($a) {
		return 'Out '.$foo.' - '.$bar.' - '.$a;
	} ,
	['foor', 'bar']
);

// return 'Out foor - bar - extra';
echo $result = Call::dispatch($cObject);

use Txiki\Callback\ICallable;

class MyObject implements ICallable
{
    public function myMethod()
    {
    }

    public function getCallable()
    {
        return function($id){
            echo 'ok '.$id;
        };
    }

    public function getParams()
    {
        return [999];
    }
}

// return 'ok 999'
echo Call::dispatch(new MyObject());
 php
e Txiki\Callback\Call;
use Txiki\Callback\CallableObject;

class DummyClass{
	public function myMethod($foo, $bar)
	{
		return 'Out '.$foo.' - '.$bar;
	}
}

$cObject = new CallableObject( 'DummyClass::myMethod' , ['foor', 'bar']);

// return 'Out foo - bar';
echo $result = Call::dispatch($cObject);