When And Where To Have Events

I wondering when am I supposed to initiate callbacks attached to events. Should I initiate the callbacks after the method or before the workings of the method?

Take the following example:




function manipulateString($string){

    $this->onManipulateString(new CEvent($this,&$string));  // launch event here

    // do something to $string

    $this->onManipulateString(new CEvent($this,&$string));  // or launch event here

    return $string;

}



I guess it depends on the semantics of your event.

If you want to process some initialization before working of the your string, you will launch the event before (and I it was my code, I would name the event ‘beforeSomething’ in this case). If you want some cleanup and postprocessing stuff, you will launch it after (and maybe name it afterSomething’ instead).

If the event does not care of this, well… just launch it when you want.