class posts
{
public function __construct($db)
{
$this->dbase = $db;
$test = new post(1, $this->dbase);
}
}
class post
{
public function __construct($id, &$j)
{
$this->ID = $id;
$this->dbase = $j;
var_dump($this); // At this point, $this-ID and $this->dbase are both null.
}
}
这是我的问题。在"post"类中,我可以倾倒$j和$id,并看到它们都完美地通过了。但是,当我尝试设置 $this->ID = $id 或 $this->dbase = $j 时,什么都没有设置。为什么会这样?
尝试:
class post
{
var ID;
var dbase;
public function __construct($id, &$j)
{
$this->ID = $id;
$this->dbase = $j;
var_dump($this); // At this point, $this-ID and $this->dbase are both null.
}
}
因为后类没有属性
试试这个
class post
{
private $ID;
private $dbase
public function __construct($id, &$j)
{
$this->ID = $i;
$this->dbase = $j;
var_dump($this); // At this point, $this-ID and $this->dbase are both null.
}
}
$test->ID
或$test->dbase
class posts
{
public function __construct($db)
{
$this->dbase = $db;
$test = new post(1, $this->dbase);
echo($test->dbase); // Here you can get all infos
}
}
class post
{
public function __construct($id, $j)
{
$this->ID = $id;
$this->dbase = $j;
}
}
new posts('foo');