-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug founded. Event 'CWebApplication.onEndRequest' attached a invalid handler 'NULL' #3158
Comments
@qiangxue this one is for you since you can get the context. |
Hi, For reproduce this error enough this code: class SiteController extends Controller {
public function actionIndex() {
error_reporting(0); // Simulate production mode
Yii::app()->setGlobalState('foo',microtime(true));
Yii::app()->attachEventHandler('onEndRequest', array($this,'whenRequestsEnds'));
Yii::app()->end();
}
public function whenRequestsEnds($event) {
echo "request ended...";
}
} Simplified code with comments and links: error_reporting(0); // Simulate production mode
$list = new CList(); // simulate CComponent::$_e variable
$list->add(0); // simulate CLogRouter::processLogs
$list->add(1); // simulate CWebApplication::saveGlobalState
$list->add(2); // simulate SiteController::whenRequestsEnds
foreach ($list as $value) { // CComponent::raiseEvent() foreach: https://github.com/yiisoft/yii/blob/1.1.14/framework/base/CComponent.php#L548
var_dump($value); // just debug
if($value == 1) { // if event handler is CWebApplication::saveGlobalState
// run event handler and if state is changed then run detachEventHandler:
// https://github.com/yiisoft/yii/blob/1.1.14/framework/base/CApplication.php#L687
// and remove handler from the list:
// https://github.com/yiisoft/yii/blob/1.1.14/framework/base/CComponent.php#L530
$list->removeAt(1);
// because the CListIterator is use reference:
// https://github.com/yiisoft/yii/blob/1.1.14/framework/collections/CListIterator.php#L41
// the $this->_d is now have 2 elements (values: 0 and 2, indexes: 0 and 1), but the $this->_c value is still 3:
// https://github.com/yiisoft/yii/blob/1.1.14/framework/collections/CListIterator.php#L43
// and for this reason the "2" index is valid here, but not existed in the $this->_d
// https://github.com/yiisoft/yii/blob/1.1.14/framework/collections/CListIterator.php#L91
// if the error_reporting is not 0 here the php is throw a notice error:
// https://github.com/yiisoft/yii/blob/1.1.14/framework/collections/CListIterator.php#L72
// Undefined offset: 2
}
} output:
expected output:
(sorry my bad english) |
You shouldn't use |
looks like a duplicate of #1191. |
@samdark Yes, you're right. I'm sorry. I just simplified this code: https://github.com/yincart/basic/blob/master/backend.php#L3 and I wrote bad comment. |
When using yii1.1.15-dev on PHP5.4, get error

More discussion here:
yincart/basic#12
Sorry, talked in Chinese.
The text was updated successfully, but these errors were encountered: