【发布时间】:2013-06-03 19:56:18
【问题描述】:
我在从子级别访问顶级变量时遇到问题。 这是一个例子......
Application.php:
class Application {
var $config;
var $db;
function __construct() {
include_once('Configuration.php');
include_once('Database.php');
$this->config = new Configuration;
$this->db = new Database;
}
}
配置.php:
class Configuration {
var $dbhost = 'localhost';
}
数据库.php:
class Database {
function __construct() {
echo parent::config->dbhost;
}
}
我很清楚,这里使用 parent 是错误的,因为子类没有扩展父类,但是我如何访问它?
谢谢。
【问题讨论】:
标签: php class variables parent