ushahidi/Ushahidi_Web — Issue #256: plugin hooks incorrectly use Event::add
Author: evoltech
Created: 2012-02-17 00:56:27+00:00
State: open

It is standard practice for plugins to implement hooks that add handlers for ushahidi events. The way this is often implemented is like:

public function __construct()
{
// Hook into routing
Event::add('system.pre_controller', array($this, 'add'));
}

When done this way you are able to interact with the class methods in the function handler, but you can't later use other Event::replace because this method is only capable of handling the list of event registrations as a hash of eventname whose value is an array of function names, as opposed to a hash of event names whose value is an array of class objects.

Consider the following from [system/core/Event.php](https://github.com/ushahidi/Ushahidi_Web/blob/master/system/core/Event.php#L131)

```
public static function replace($name, $existing, $callback)
{

if (empty(self::$events[$name]) OR ($key = array_search($existing, self::$events[$name], TRUE)) === FALSE)
return FALSE;

```

The reason passing in calling
Event:add($event, array($this, $function_name));
works is because the 2nd argument is passed along to call_user_func which permits this.

Since the version of Kohana that Ushahidi is using is no longer supported I suppose we are maintaining it, in which case this is a bug in [system/core/Event.php](https://github.com/ushahidi/Ushahidi_Web/blob/master/system/core/Event.php#L131)