Skip to content

axypro/callbacks

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
doc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

axy\callbacks: the callback extended format

Latest Stable Version Minimum PHP Version Build Status Coverage Status License

  • The library does not require any dependencies.
  • Tested on PHP 5.4+, PHP 7, HHVM (on Linux), PHP 5.5 (on Windows).
  • Install: composer require axy/callbacks.
  • License: MIT.

Documentation

Examples

function sum($a, $b)
{
    return $a + $b;
}

Standard callback:

$callback = new Callback('sum');

echo $callback(2, 2);

Binging arguments:

$callback = new Callback('sum', [3]);

echo $callback(4); // 3 + 4 = 7

Binging context:

class MyClass
{
    public function getEventHandler()
    {
        return new Callback([$this, 'onEvent'], ['click'], true);
    }

    private function onEvent($event)
    {
        echo 'Event '.$event.'!';
    }
}

$obj = new MyClass();
$handler = $obj->getEventHandler();

// click
$handler(); // "Event click!". Private method was called

About

Extension of php-callback format

Resources

License

Stars

Watchers

Forks

Packages

No packages published