php错误 session_start()方的位置不正确导致定义的常量ROOT未定义

 

// 开启session

session_start();

define('ROOT',str_replace('\\','/',dirname(dirname(__FILE__))).'/');

define('DEBUG',true);
/*
require(ROOT.'include/conf.class.php');//载入配置文件类
require(ROOT.'include/db.class.php');//载入数据库类
require(ROOT.'include/mysql.class.php');//载入数据库类
require(ROOT.'Model/Model.class.php');//载入模型基类
require(ROOT.'Model/TestModel.class.php');//载入数据表的model类
require(ROOT.'include/Log.class.php');//载入log日志类
require(ROOT.'include/lib_base.php');//载入基本函数文件
*/
require(ROOT.'include/lib_base.php');//载入基本函数文件
function __autoload($classname){
if(strtolower(substr($classname,-5))=='model'){
require(ROOT.'Model/'.$classname.'.class.php');
}elseif(strtolower(substr($classname,-4))=='tool'){
require(ROOT.'tool/'.$classname.'.class.php');
}else{
require(ROOT.'include/'.$classname.'.class.php');
}

}

//require(ROOT.'tool/CartTool.class.php');
//过滤参数,用递归的方式过滤$_GET,$_POST,$_COOKIE,$_SESSION,
$_GET = _addslashes($_GET);
$_POST = _addslashes($_POST);
$_COOKIE = _addslashes($_COOKIE);

//加入购物车

$cart =CartTool::getCart();//获取购物车实例  单例模式

报如下错误: Notice: Use of undefined constant ROOT - assumed 'ROOT' in D:\wamp\www\study\moonshop\include\init.php on line 30 Warning: require(ROOTtool/CartTool.class.php) []: failed to open stream: No such file or directory in D:\wamp\www\study\moonshop\include\init.php on line 30 Fatal error: require() []: Failed opening required 'ROOTtool/CartTool.class.php' (include_path='.;C:\php5\pear') in D:\wamp\www\study\moonshop\include\init.php on line 30
 
如下代码 就正常 只是改了session_start()位置
 
 
//初始化当前的绝对路径 //echo __FILE__.__DIR__; define('ROOT',str_replace('\\','/',dirname(dirname(__FILE__))).'/'); define('DEBUG',true); /* require(ROOT.'include/conf.class.php');//载入配置文件类 require(ROOT.'include/db.class.php');//载入数据库类 require(ROOT.'include/mysql.class.php');//载入数据库类 require(ROOT.'Model/Model.class.php');//载入模型基类 require(ROOT.'Model/TestModel.class.php');//载入数据表的model类 require(ROOT.'include/Log.class.php');//载入log日志类 require(ROOT.'include/lib_base.php');//载入基本函数文件 */ require(ROOT.'include/lib_base.php');//载入基本函数文件 function __autoload($classname){
if(strtolower(substr($classname,-5))=='model'){
require(ROOT.'Model/'.$classname.'.class.php'); }elseif(strtolower(substr($classname,-4))=='tool'){
require(ROOT.'tool/'.$classname.'.class.php'); }else{
require(ROOT.'include/'.$classname.'.class.php'); }
} //require(ROOT.'tool/CartTool.class.php'); //过滤参数,用递归的方式过滤$_GET,$_POST,$_COOKIE,$_SESSION, $_GET = _addslashes($_GET); $_POST = _addslashes($_POST); $_COOKIE = _addslashes($_COOKIE);
// 开启session session_start();
//设置报错级别 if(defined('DEBUG')){
  error_reporting(E_ALL); }else{
  error_reporting(0); }