Problem defining YII_DEBUG mode

I have an altered entry script that uses alternate configuration for different environments. I have tried to change the entry script so that all environments except aa-prod-serve (Production Server) will automatically define YII_DEBUG = true, and this will determine if the Web Optimizer is used or not (CSS/JS compression).

However, the Web Optimizer is never applied. It is like no matter what I do the YII_DEBUG is always defined. Can anyone spot what I’m doing wrong?




<?php

// change the following paths if necessary

$globals=dirname(__FILE__).'/protected/globals.php';

$yii=dirname(__FILE__).'/../yii/framework/yii.php';


require_once($globals);

require_once($yii);


// Option to force debug mode from here

$forceDebug = false;


/**

 * If a host is found, try to load the config

 */

$hostKey = aa_instance();

if ($hostKey) // Found valid host

{

    // If not the production server, enable debug mode

    if($hostKey!='aa-prod-serve')

    {

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

    }


    // Web Optimizer

    if (!defined('YII_DEBUG'))

    {

        require('web-optimizer/web.optimizer.php');

    }

    

    $config=dirname(__FILE__).'/protected/config/'.$hostKey.'.php';

    $default=dirname(__FILE__).'/protected/config/main.php';

	

    if (file_exists($config))

    {

        Yii::createWebApplication($config)->run();

    }   

    elseif (file_exists($default))

    {

        Yii::createWebApplication($default)->run();

    }   

    else

    {

		print ("Three things are certain:<br>Death, taxes, and $hostKey config file doesn't exist.<br>Guess which has occurred.");

		exit;

	}    


    // Web Optimizer

    if (!defined('YII_DEBUG'))

    {

        $web_optimizer->finish();

    }

}

else // No valid host found

{

	print ("You step in the stream,<br>but the water has moved on.<br>Host not found.");

	exit;

}



It is defined to false in YiiBase.php so your test will fail




require_once($yii);



/Tommy

You need to define YII_DEBUG before you include yii.php/yiilite.php.

I would say: don’t rely on “defined(YII_DEBUG)” for sensing the state of YII_DEBUG. And don’t rely on the boolean expression “defined(something) or define_something”. When testing with 5.2.9 it seems defined() isn’t needed at all?

/Tommy