model event handler self-detach

Has the following example code:

Model:




class SimpleModel extends CFormModel

{

	public function method1()

	{

		echo 'Run method 1';

		$this->detachEventHandler('onBeforeValidate',array($this,'method1'));

	}

	public function method2()

	{

		echo 'Run method 2';

		$this->detachEventHandler('onBeforeValidate',array($this,'method2'));

	}

}



And controller:




$model=new SimpleModel;

$model->attachEventHandler('onBeforeValidate',array($model,'method1'));

$model->attachEventHandler('onBeforeValidate',array($model,'method2'));

$model->validate();



This may be needed if you wish to run method only on first event dispatch and then detach it.

If you use only one event handler everything works fine, but if there is two,

on attempt to run method2 you will receive exception:




Event "SimpleModel.onbeforevalidate" is attached with an invalid handler "NULL"



Code line 580 of framework/base/CComponent.php

As I think:

This happends cause after detaching method1 handler (CList::removeAt(), [line 190]) he decreases size of

CList of handlers and foreach expression at CComponent::raiseEvent(), [line 553] tries to run

missing element (size+1) wich and throws this exception.

I know that this is pretty strange example can be solved by many other ways and maybe not a bug it self,

but maybe its better to allow event handlers to detach themselves freely.