2011-07-14 61 views
0

嗨,我有以下目錄結構:PHP語法錯誤問題

Main Folder -> Classes -> user_classes

都互相嵌套。我有內部類目錄下面的文件

always_include_top.php 
custom_error_handler.php 
config.php 
database.php 

外面的database.php中文件如下:

<?php 
include_once("always_include_top.php"); 

include_once("config.php"); 
include_once("custom_error_handler.php"); 

include_once ("user_classes/newDatabase.php"); 

class Database extends newDatabase 
{ 

// some more code... with extra functions 
    public function dbBackUp($backupfile = NULL) 
    { 
     //code... 
    } 
} 
?> 

我在用戶user_classes目錄下面的文件

newDatabase.php

此文件的代碼示例是

<?php 
include_once("../always_include_top.php"); 

include_once("../config.php"); 
include_once("../custom_error_handler.php"); 
error_reporting(E_ALL); 

class newDatabase 
{ 
    // my code goes here 
} 

?> 

爲什麼我會收到以下錯誤類/ database.php中(沒有在類錯誤/ user_classes/newDatabase.php

Warning: include_once(../always_include_top.php) [function.include-once]: failed to open stream: No such file or directory in E:\wamp\www\greeting_cards\adm\classes\user_classes\database.php on line 2

Warning: include_once() [function.include]: Failed opening '../always_include_top.php' for inclusion (include_path='.;C:\php\pear') in E:\wamp\www\greeting_cards\adm\classes\user_classes\database.php on line 2

Warning: include_once(../config.php) [function.include-once]: failed to open stream: No such file or directory in E:\wamp\www\greeting_cards\adm\classes\user_classes\database.php on line 4

Warning: include_once() [function.include]: Failed opening '../config.php' for inclusion (include_path='.;C:\php\pear') in E:\wamp\www\greeting_cards\adm\classes\user_classes\database.php on line 4

Warning: include_once(../custom_error_handler.php) [function.include-once]: failed to open stream: No such file or directory in E:\wamp\www\greeting_cards\adm\classes\user_classes\database.php on line 5

Warning: include_once() [function.include]: Failed opening '../custom_error_handler.php' for inclusion (include_path='.;C:\php\pear') in E:\wamp\www\greeting_cards\adm\classes\user_classes\database.php on line 5

Fatal error: Cannot redeclare class Database in E:\wamp\www\greeting_cards\adm\classes\database.php on line 12

我想這兩個文件單獨編譯。因爲我會根據頁面類型將文件包含在其他文件中。這裏包括什麼問題?

+0

你在'user_classes/newDatabase.php'中有什麼? – MGwynne

+0

@MGwynne我已經把它放在「*我在用戶user_classes目錄中有以下文件*」部分。看看 – footy

+0

我想你可以將'include_once()'database.php中的路徑更改爲'include_once(「classes/always_include_top.php」);' – jeni

回答

1

當您使用include_once()時,它不會更改到特定文件所在的目錄並在那裏執行它,它會在當前文件的上下文中執行該文件的內容。所以,類/ user_classes/database.php就像在classes文件夾中一樣執行。 「..」指的是在這種情況下的主文件夾,所以它正在查找主文件夾中的前三個文件。這些文件不在主文件夾中,因此會給出警告。