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: æ©è¯´åï¼æè¿ä»¥ä¸ºé½æ¯å¤å½äººå¢ã //å®ä¹ç½ç«è·ç®å½ 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ç Previous Comments: ------------------------------------------------------------------------ [2012-09-10 07:53:37] larue...@php.net ä½ ç¨ä¸ææè¿°å§, æå®å¨çä¸æä½ è¯´ä»ä¹é误.... å¦å¤, 请æä¾ä¸ä¸ªå¯ä»¥æ£å¸¸è¿è¡çå¯éè¯èæ¬. (you can re-describe this problem in chinese, previous one is hard to read). thanks ------------------------------------------------------------------------ [2012-09-10 07:44:44] ian dot xspace at yahoo dot cn private function sysModule() { //error writing éè¯¯åæ³ return array( 'M'=>MODELS, 'V'=>VIEWS, 'C'=>CTRLS, 'L'=>LIBS, 'P'=>PLNS, 'H'=>HLP ); //right wring æ£ç¡®åæ³ return array( 'M'=>MODELS, 'V'=>VIEWS, 'C'=>CTRLS, 'L'=>LIBS, 'P'=>PLNS, 'H'=>HLP ); } //common.php load some calss file //Assume $type = 'M.className'; function loadSomeClass($type) { $csName = substr($cs, 2); $type = strtoupper(strtok($cs, '.')); $moArr = SYS::getSys('sysModule'); //find module require_once($moArr[$type].DS."{$csName}.php"); //Error wording actually some successful and some not successful //å¨éè¯¯åæ³ä¸å± ç¶æçè½æåæçä¸è½æå } ------------------------------------------------------------------------ [2012-09-07 17:19:21] larue...@php.net Thank you for this bug report. To properly diagnose the problem, we need a short but complete example script to be able to reproduce this bug ourselves. A proper reproducing script starts with <?php and ends with ?>, is max. 10-20 lines long and does not require any external resources such as databases, etc. If the script requires a database to demonstrate the issue, please make sure it creates all necessary tables, stored procedures etc. Please avoid embedding huge scripts into the report. ------------------------------------------------------------------------ [2012-09-07 05:28:30] ian dot xspace at yahoo dot cn Description: ------------ <?php //OS: win7 php:5.3.16 mysql:5.5 //such as [Some code snippets] //Assume WEB_ROOT = 'E:/www'; define('WEB_ROOT', strtr(dirname(__FILE__), '\\', '/')); //define the web system directory 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'); //define associate /* Error writing */ class SYS { 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 load some calss file //Assume $type = 'M.className'; function loadSomeClass($type) { $csName = substr($cs, 2); $type = strtoupper(strtok($cs, '.')); $moArr = SYS::getSys('sysModule'); //find module require_once($moArr[$type].DS."{$csName}.php"); } //bugs: In accordance with the above wording some successful and some can not successfully ????? /* private function sysModule() { return array( 'M'=>MODELS, 'V'=>VIEWS, 'C'=>CTRLS, 'L'=>LIBS, 'P'=>PLNS, 'H'=>HLP ); } */ ?> Test script: --------------- <?php //OS: win7 php:5.3.16 mysql:5.5 //such as [Some code snippets] //Assume WEB_ROOT = 'E:/www'; define('WEB_ROOT', strtr(dirname(__FILE__), '\\', '/')); //define the web system directory 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'); //define associate /* Error writing */ class SYS { 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 load some calss file //Assume $type = 'M.className'; function loadSomeClass($type) { $csName = substr($cs, 2); $type = strtoupper(strtok($cs, '.')); $moArr = SYS::getSys('sysModule'); //find module require_once($moArr[$type].DS."{$csName}.php"); } //bugs: In accordance with the above wording some successful and some can not successfully ????? /* private function sysModule() { return array( 'M'=>MODELS, 'V'=>VIEWS, 'C'=>CTRLS, 'L'=>LIBS, 'P'=>PLNS, 'H'=>HLP ); } */ ?> Expected result: ---------------- private function sysModule() { return array( 'M'=>'MODELS', 'V'=>'VIEWS', 'C'=>'CTRLS', 'L'=>'LIBS', 'P'=>'PLNS', 'H'=>'HLP' ); } error writing! why require_once some successful and some error ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=63026&edit=1