我知道這是一個語法錯誤,但我沒有看到我做了什麼錯。該錯誤是我不明白爲什麼我得到這個錯誤
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting T_STRING or T_VARIABLE or '{' or '$' on line 8
而且代碼
class Person {
public $isAlive=true;
public $firstname;
public $lastname;
public $age;
public function __construct()
{
$teacher->"boring"=$firstname;
$teacher->"12345"=$lastname;
$teacher->12345=$age;
$student->"Natalie Euley"=$firstname;
$student->"Euley"=$lastname;
$student->19=$age;
}
public function greet()
{
return "Hello, my name is ".$this->firstname." ".$this->lastname. "Nice to meet you!";
}
}
$student = new Person();
$teacher = new Person();
echo $student->greet();
echo $techer->greet();
我現在明白了。 CodeAcademy有混亂的方向。我現在得到如何去做。感謝您解釋一切!
你的類成員變量賦值是無效的語法。事實上,他們倒退了。我以前從來沒有見過。 –
它是一個令人印象深刻的錯誤嘗試 – 2014-02-10 19:08:11
@Dagon:這是怎樣的建設性?每個人都曾經是初學者,並且**人不是天生就知道PHP及其語法**。我同意這實際上是一個低質量的問題,但我個人覺得這樣的評論是粗魯/有害的,並且具有零關聯性。 –