我只是想确保我做得正确。我有点困惑$this->parameter
,$parameter
和public $parameter
这是我正在做的一个例子。我希望能够使用该$instance->parameter
方法访问任何被声明为公共的东西。这是否意味着点访问也可以工作?我是多余的吗?
class Email {
public $textBody;
public $attachments;
public $subject;
public $emailFolder;
function __construct($header) {
$this->head = $header;
$this->attachments = [];
preg_match('/(?<=Subject: ).*/', $this->head, $match);
$this->subject = $match[0];
if ($this->subject) {
$this->subject = "(No Subject)";
}
preg_match('/(?<=From: ).*/', $this->head, $match);
$this->fromVar = $match[0];
preg_match('/(?<=To: ).*/', $this->head, $match);
$this->toVar = $match[0];
preg_match('/((?<=Date: )\w+,\s\w+\s\w+\s\w+)|((?<=Date: )\w+\s\w+\s\w+)/', $this->head, $match);
$this->date = $match[0];
$this->date = str_replace(',', '', $this->date);
$this->textBody = "";
}
function generateParsedEmailFile($textFile) {
if (!(file_exists("/emails"))) {
mkdir("/emails");
}
$this->emailFolder =
$filePath = "/emails/".$this->subject.$this->date;
while (file_exists($filePath)) {
$filePath = $filePath.".1";
}
# ......code continues
}
}