Very obvious questions about YII_DEBUG

Hi there,

I know the answer is obvious, as those are very basics of PHP, but I can’ find it, erh! :[

I’m using piece of code like this:

$error_message.= print_r(defined('YII_DEBUG'), TRUE).'<br />';

$error_message.= 'YII_DEBUG = '.(defined('YII_DEBUG')) ? 'true' : 'false';

if('YII_DEBUG' == TRUE) $error_message.= '<br />YII_DEBUG = true'; else '<br />YII_DEBUG = false';


And here are questions:

  1. Why all three lines are returning TRUE, if YII_DEBUG constant is actually set to FALSE (which I can observe by how exceptions messages are being displayed).

  2. Why second line is just displaying “true” (omitting 'YII_DEBUG = ’ part)?

  3. Why exception messages are displayed in English (“CDbConnection failed to open the DB connection”) when YII_DEBUG is set to FALSE and in Polish (“Obiekt CDbConnection: błąd przy otwieraniu połączenia do bazy danych”)? Application is configured to use Polish (‘language’=>‘pl’).

EDIT: Should be if(YII_DEBUG == TRUE) (without quotes!) in the last line of course, but it doesn’t change anything here - still showing TRUE, when YII_DEBUG is set to FALSE! :expressionless:

You cannot change the value of Yii_debug once it is set, as it is a constant.

You should change it in the index.php, where it is setted:

Change from:

// remove the following lines when in production mode

defined('YII_DEBUG') or define('YII_DEBUG',true);

// specify how many levels of call stack should be shown in each log message

defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);


// remove the following lines when in production mode

//defined('YII_DEBUG') or define('YII_DEBUG',true);

// specify how many levels of call stack should be shown in each log message

//defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);

I was not trying to change it! I was trying to read its value.

It was my mistake. Found out that mistakenly took PHP’s defined as function for reading constant value while it is used to check, whether it is only defined.

But I still can’t understand, why error messages gets auto-magically translated back to English (or to be more precise - are NOT being translated into Polish) when YII_DEBUG is set to FALSE?

Which error messages?

You have to do it this way:

'YII_DEBUG = '.(defined('YII_DEBUG') ? 'true' : 'false');

But I wonder what you are doing? Why not just do var_dump(YII_DEBUG) in order to proof the debugging state?

// Also defined() will return true if YII_DEBUG is defined. Doesn’t matter if it’s true or false. It will always return true.

Yes. That is exactly what I wrote below my question! :]

I noticed this only on DB connection exception message, but believe, it will be related to any exception. As I wrote earlier:

I’m getting “CDbConnection failed to open the DB connection”, when YII_DEBUG is set to FALSE, why I should get Polish translation of this message (as I’m getting, when YII_DEBUG is set to TRUE) since application language is defined to ‘pl’.

I just tried with polish language. Same message with YII_DEBUG set to true or false.

Well, I know that I have some false reports in the history of this forum! :] But, believe me, I wouldn’t report something that I wouldn’t be so sure about…

I agree that I slightly modified translation files to suit my needs, but these was only string or text-based changes (translation tune-up) and I don’t believe they could influence current situation in any way.

Take a look at attached screen-shots.





Situation, as described above. When YII_DEBUG is set to TRUE, I see translated message (as excepted) plus additional information returned from DB driver. When YII_DEBUG is set to FALSE, message is not translated (this is the same message - i.e. the same error or exception, tested in the same situation) and (also as excepted) no additional information from DB driver added, as it isn’t added in production mode.


Can’t reproduce it. Reduced test case will help a lot.

First of all - I don’t know what happened or what I did in my project as up until yesterday I wasn’t using YII_DEBUG set to False. All the time my application went in debug mode.

These screenshots are comming from my older version of error handler, before I introduced this solution proposed by Yii.

This is the code of my Controller::onBeginRequest, where I previously holded my error handler:

public static function beginRequest()








                            	//Send current user ID to database...

                            	$sql = 'BEGIN LWWW.SetCurrentUser('.app()->user->id.'); END;';





    	catch(Exception $e)


            	//Here - my so called error handler...

            	//...some error text formating routines...

            	//...line directly responsible for displaying exception text...

            	$error_message.= '<div class="flash-error">'.$e->getMessage().'</div>';

            	//...some other errror text formating routines...



I priovided only the line that is printing out message being displayed once in Polish, once in English. All other lines hidden to short code.

I don’t know what else I could provide?