如果我有以下代码:
namespace System
{
namespace Models
{
$modelsFolder = "Models";
require_once( "../$modelsFolder/Site.php" );
require_once( "../$modelsFolder/Session.php" );
require_once( "../$modelsFolder/Form.php" );
require_once( "../$modelsFolder/Recaptcha.php" );
require_once( "../$modelsFolder/AppCred.php" );
require_once( "../$modelsFolder/User.php" );
require_once( "../$modelsFolder/Database.php" );
}
namespace Controllers
{
namespace System\Models;
$db = new Database();
}
}
如果在我的控制器文件中,我总是声明:
namespace System\Controllers;
$db->Query(); // will this work because it has been declared in the namespace Controllers?
$db 的实例会被带到这个文件中吗?还是我需要在命名空间之外声明我的 $db 并在包含控制器文件之前包含它?