Bug #63026 [Fbk]: require_once error

From: Date: Wed, 12 Sep 2012 10:25:08 +0000
Subject: Bug #63026 [Fbk]: require_once error
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-173365@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=63026&edit=1

 ID:                 63026
 Updated by:         laruence@php.net
 Reported by:        ian dot xspace at yahoo dot cn
 Summary:            require_once error
 Status:             Feedback
 Type:               Bug
 Package:            *Compile Issues
 Operating System:   windows 7
 PHP Version:        5.3.16
 Block user comment: N
 Private report:     N

 New Comment:

你从哪里看出来和大小写有关系的?


Previous Comments:
------------------------------------------------------------------------
[2012-09-12 10:15:04] reeze@php.net

看你这情况,有可能是你的大小写问题,
你是直接require_once的,如果大小写错了是有问题的。
为了好调试,你可以在require_once
前加一个if(!file_exists($file) {die($file not found)}
检查一下。
你确认一下文件的确存在吧。

同时,是在不行,把你的代码完整打包传到某个地方吧。。

------------------------------------------------------------------------
[2012-09-12 02:03:08] laruence@php.net

那些类名可以正确加载
,那些类名不可以?  你举个例子?

------------------------------------------------------------------------
[2012-09-12 01:56:19] ian dot xspace at yahoo dot cn

//init.php 定义网站目录
/***************************网站目录定义***************************/
define('THEME', 'default');
//define('TEMP', WEB_ROOT.DS.'temp');
//define('LIBS', WEB_ROOT.DS.'libs');
define('VIEWS', WEB_ROOT.DS.'views');
define('LOGS', VIEWS.DS.'logs');
define('DYN', VIEWS.DS.'dynamic');
define('HLP', WEB_ROOT.DS.'helpers');
//define('PLNS', WEB_ROOT.DS.'plugins');
define('CONFS', WEB_ROOT.DS.'configs');
define('MODELS', WEB_ROOT.DS.'models');
define('CTRLS', WEB_ROOT.DS.'controls');
//SYS.php 
sysModule函数里的对应关系为错误写法,正确写法应该是'M'=>MODELS后者无需单引号
class SYS
{
	//sysModule系统目录映射
	private function sysModule()
	{
		return array(
		'M'=>MODELS, 'V'=>VIEWS,
		'C'=>CTRLS, 'L'=>LIBS,
		'P'=>PLNS, 'H'=>HLP
		);
	}
	//getSys获取相应配置
	public static function getSys($fun)
	{
		return self::$fun();
	}
}
//common.php 其中一个函数,加载所需要的类
class Common
{
	//loadCS
	protected function loadCS($cs)
	{
		$csName = substr($cs, 2);
		$type = strtoupper(strtok($cs, '.'));
		$moArr = SYS::getSys('sysModule'); //直接定位		
		require_once($moArr[$type].DS."{$csName}.php");
// 		switch($type)  以上将会获取更快执行速度
// 		{
// 			case 'M':
// 				require_once(MODELS.DS."$csName.php");
// 			break;
// 			case 'V':
// 				require_once(VIEWS.DS."$csName.php");
// 			break;
// 			case 'C':
// 				require_once(CTRLS.DS."$csName.php");
// 			break;
// 			case 'L':
// 				require_once(LIBS.DS."$csName.php");
// 			break;
// 			case 'P':
// 				require_once(PLNS.DS."$csName.php");
// 			break;
// 			case 'H':
// 				require_once(HLP.DS."$csName.php");
// 			break;
// 			default:
// 				JS::willJS('alertMsg', '调用失败!');
// 		}
		$CS = ucfirst($csName);
		return new $CS();
	}
}

//index.php 首页调用其它类
//Index
class Index extends IAN_C
{
 	//__construct
	public function __construct()
	{
           $obj = $this->loadCS('M.share_model');//调用其它类
          
//你可以多调用几个类,在上面错误写法情况下,有的类可以调用成功,有的失败
           //sysModule
里的对应关系,应该这么写'C'=>CTRLS,后者无需引号
	}

}
new Index

//大哥你要是再看不明白,我也没辙了

------------------------------------------------------------------------
[2012-09-12 01:48:03] ian dot xspace at yahoo dot cn

早说啊,我还以为都是外国人呢。
//定义网站跟目录 init.php
define('WEB_ROOT', strtr(dirname(__FILE__), '\\', '/'));
//定义网站的其它目录
define('TEMP', WEB_ROOT.DS.'temp');
define('LIBS', WEB_ROOT.DS.'libs');
define('VIEWS', WEB_ROOT.DS.'views');
//下面是我写的一个类 sys.php
class SYS
{
       
//这个是每个目录对应的简写,但是这是错误写法,可在后期的程序调用中居然有的
        //可以成功有的失败了  $moArr =
SYS::getSys('sysModule');
        //require_once($moArr[$type].DS."{$csName}.php");
这样可以直接
       
//引入所需要的文件,避免使用switch浪费时间
        /*
// 		switch($type)  以上将会获取更快执行速度
// 		{
// 			case 'M':
// 				require_once(MODELS.DS."$csName.php");
// 			break;
// 			case 'V':
// 				require_once(VIEWS.DS."$csName.php");
// 			break;
// 			case 'C':
// 				require_once(CTRLS.DS."$csName.php");
// 			break;
// 			case 'L':
// 				require_once(LIBS.DS."$csName.php");
// 			break;
// 			case 'P':
// 				require_once(PLNS.DS."$csName.php");
// 			break;
// 			case 'H':
// 				require_once(HLP.DS."$csName.php");
// 			break;
// 			default:
// 				JS::willJS('alertMsg', '调用失败!');
// 		}
       */
      
//这里是系统目录对应的单词简写,但是这是错误写法
       //正确写法应该是  'M'=>MODELS
后面无需加单引号(虽然是错误写法但是使用的时候
      
//有的可以正常使用有的不能正常使用)
	private function sysModule()
	{
		return array(
				'M'=>'MODELS', 'V'=>'VIEWS',
				'C'=>'CTRLS', 'L'=>'LIBS',
				'P'=>'PLNS', 'H'=>'HLP'
		);
	}
	
	public static function getSys($fun)
	{
		return self::$fun();
	}
}

//common.php 其它程序共享类
class Common
{
  
//类中的一个函数用于调用所需要的其他类
   public function loadSomeClass($type)
   {
	$csName = substr($cs, 2);
	$type = strtoupper(strtok($cs, '.'));
	$moArr = SYS::getSys('sysModule'); //find module
	require_once($moArr[$type].DS."{$csName}.php");
   }
}

//index.php 比如在index.php页面里调用其他类文件
class Index
{
   public function __construct()
   {
     require_once 'common.php';
     $com = new Common();
    
$com->loadSomeClass('M.db_model');//引入这个类文件或者mvc里的任何一个文件
    //问题就出在这里  'M'=>'MODELS',
这种写法是有错的,但是调用loadSomeClass
   
//时候居然有的类可以正确加载而有的类不能正确加载
   }
}
new Index();

//要是还看不明名,你告诉我从哪里上传文件啊,或者我的QQ是995668790,以前我在你的博客里和你
聊过ian,就说有bug的

------------------------------------------------------------------------
[2012-09-10 07:53:37] laruence@php.net

你用中文描述吧,
我实在看不懂你说什么错误.... 
另外,
请提供一个可以正常运行的可重试脚本.

(you can re-describe this problem in chinese, previous one is hard to read).

thanks

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=63026


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=63026&edit=1


Thread (12 messages)

« previous php.bugs (#173365) next »