【发布时间】:2015-11-21 04:14:29
【问题描述】:
我唯一想要实现的是能够从B类访问A类中的Sql属性,但我的理解必须完全离网。
我试过了:
class A {
public $Sql; /*object*/
public function __construct() {
$this->Sql = new MySQLi("localhost", "user", "password", "database");
}
}
class B extends A {
public function __construct() {
$this->foo();
}
public function foo() {
var_dump($this->Sql); // NULL
var_dump(parent::Sql); // Error due to Sql not being a constant, can't set an object as a constant.
}
}
$A = new A();
$B = new B();
但是代码并没有像我希望的那样运行。
希望有人能指出我出错的正确方向。
【问题讨论】:
标签: php oop properties constructor parent