我正在尝试编写以下代码,虽然它是错误的,但它可能会证明我为什么要这么做.
class myClass
{
private $name = "";
private $startAddress = new myAddress(); // this is the issue
private $endAddress = new myAddress(); // this is the issue
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
谢谢
<?php
class myClass {
private $endAddress;
public function __construct() {
$this->endAddress = new myAddress();
}
}
Run Code Online (Sandbox Code Playgroud)