我以前没有写过 OOP 代码,我总是尽量避免额外的击键。无论如何,我正在冒险,因为它应该增加可读性。
无论如何,我无法让我的课程能够访问彼此的方法。
这是我的设置:
$conf = new Conf(); // boot up!
// Include dependencies, system files and other functions
require_once $conf->getIncludePath() . 'error.php';
require_once $conf->getIncludePath() . 'pool.php';
require_once $conf->getIncludePath() . 'database.php';
require_once $conf->getIncludePath() . 'api.php';
require_once $conf->getIncludePath() . 'user.php';
require_once $conf->getIncludePath() . 'forms.php';
require_once $conf->getIncludePath() . 'page.php';
require_once $conf->getIncludePath() . 'resources.php';
$error = new Error();
$pool = new Pool();
$db = new Database();
$api = new Api();
$user = new User();
$forms = new Forms();
$page = new Page();
$resources = new Resources();
我的问题是,我如何得到它,以便User
类中的方法可以在里面运行查询方法Database
,比如获取他们的信息?
我知道global $db; global $user; etc.
在每一种方法中都使用过,但是有没有办法让我得到这些变量而不必每次我想使用它们时都重新声明它们?
谢谢
码头