Bug #63026 [Com]: require_once error

From: Date: Thu, 13 Sep 2012 05:46:51 +0000
Subject: Bug #63026 [Com]: require_once error
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-173398@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
 Comment by:         ian dot xspace at yahoo dot cn
 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:

return array(
				'M'=>'MODELS', 'V'=>'VIEWS',
				'C'=>'CTRLS', 'L'=>'LIBS',
				'P'=>'PLNS', 'H'=>'HLP'
		);
关键是这种情况下我调用很多类都成功了,不是应该失败的吗,下面才是正确写法
		return array(
				'M'=>MODELS, 'V'=>VIEWS,
				'C'=>CTRLS, 'L'=>LIBS,
				'P'=>PLNS, 'H'=>HLP
		);


Previous Comments:
------------------------------------------------------------------------
[2012-09-12 10:30:46] reeze@php.net

“$obj = $this->loadCS('M.share_model');//调用其它类
          
//你可以多调用几个类,在上面错误写法情况下,有的类可以调用成功,有的失败
           //sysModule
里的对应关系,应该这么写'C'=>CTRLS,后者无需引号
”
require_once的路径是直接拼的,而且不是autoload,
他这里没有其他的例子,如果部分类名大小写错了,就会出现部分类找不到的情况。

在require前增加个检查就能确认或者排除这个问题了

------------------------------------------------------------------------
[2012-09-12 10:25:08] laruence@php.net

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

------------------------------------------------------------------------
[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

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

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


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 (#173398) next »