Hello,
I am trying to figure out why it is necessary to have a method named after the event existing to benefit from CComponent / CEvent mechanism.
Here is what I would like to do :
class foo extends CComponent
{
public function doSomeStuff()
{
/* ... */
$this->raiseEvent( 'onStuffDone', new CEvent() );
}
}
$o = new foo();
$o->onStuffDone = create_function( '$event', 'echo "Stuff Done !"' ); // will go through CComponent::__set
$o->doSomeStuff();
I expect “Stuff done !” to be printed.
The call to CComponent::__set
fails if I do not implement foo::onStuffDone(
) method. But why on earth would I do that ?
Updating both CComponent __get and __set magic methods as below just work as I expect:
elseif(strncasecmp($name,'on',2)===0 /* && method_exists($this,$name)*/)
What am I missing here ?
Thanks if you have any clue !