How to log PHP errors?

Hi, for example this code:




public function actionDoIt()

{

    $data = array();

    $var = $data['SomeIndex'];

}



Yii’s error message is:




PHP Error


Undefined index: SomeIndex



How to log this (and other) PHP errors to log file and display own error page?

Plenty wiki on how to do that: http://www.yiiframework.com/search/?q=log&type=wiki&lang=

This is not a Yii error, but a PHP error and it’s caused by having E_STRICT set in error_reporting. Check the PHP manual for further information on what values are available for error_reporting.

Yes, it’s PHP error, but it is shown in Yii’s style (in Yii’s exception design).

Question is, how to handle, how PHP errors in Yii look like?

See here:

http://www.yiiframework.com/doc/guide/1.1/en/topics.error

You could attach a handler to CApplications onError event. But you’d have to do this very early to cover as many situations as possible with your handler. Probably right in index.php before you call run() on your application object.

If all you need is logging, catch the error and warning log levels. Not sure if they contain these messages. But worth a try.

http://www.yiiframework.com/doc/guide/1.1/en/topics.logging