嗨,我只是學習PHP,我正在嘗試各種代碼示例/練習。下面是一個PHP - 語言新手
<?php
// class definition
class Bear
{
// define properties
public $name;
public $weight;
public $age;
public $colour;
public $sex;
// constructor
public function _construct()
{
$this->age = 0;
$this->weight = 100;
$this->colour = "Brown";
}
}
// create instance
$baby = new Bear;
$baby->name = "Baby bear";
$sex->sex = "Male";
echo $baby->name." is ".$baby->colour." and weighs ".$baby->weight." units at birth and his sex is ".$baby->sex;
?>
當我運行這個文件,它返回
寶寶熊和出生時體重的單位和他的性是
它不拿起變量。 任何建議都會很棒。 謝謝
'$性別> sex'是什麼呢?'$愛嬰>性別'應該是'$ sex-> sex'或者這個'$ sex-> sex'應該是'$ baby-> sex' ... – devpro
'_construct()'應該是'__construct()'(2個下劃線);年齡,顏色和重量不在構造函數中設置,因爲它不是構造函數。 – CD001
感謝所有幫助工作現在好了 – Mike