Is it possible to temporarily disable the Yii error handler to allow a PHP warning through? Or (after seeing what I’m trying to do)… am I going about this all wrong and is there a better way to approach this?
I guess this could apply to ANY situation when you want to capture a PHP warning, but for me, I’m trying to rename a folder. The function doesn’t throw an exception but does return a true/false based on the result. During testing, I forced it to error, but the application isn’t handling it how I expected. I want to log the error and continue processing, but the Yii error handler is kicking in and not letting me check the result of the PHP function rename().
Config:
'errorHandler'=>array(
'errorAction'=>'site/error',
),
Code:
if ( rename('/path/to/current/folder', '/path/with/new/name') ) { // with Yii's error handler enabled, the code stops here
echo 'Success. The folder was renamed';
}
else {
echo 'Boo. The folder was NOT renamed';
}
Outside of Yii (in a plain 'ole PHP file), this works perfectly. Inside Yii, not so much.
If I disable the Yii error handler, it works ok. But I don’t want to disable it for my whole application just to suit this one situation.
defined('YII_ENABLE_ERROR_HANDLER') or define('YII_ENABLE_ERROR_HANDLER',false);
Can I disable the event handler before performing the function and then re-enable again after?
Yii::app()->attachEventHandler('onError',null);
After all that… the question is, what’s the best way to capture/handle PHP warnings and continue with the current script without disabling Yii’s error handler for the entire application?
Thanks in advance!