求大姐幫小弟我看看這個程式哪點出毛病了

來源:互聯網
上載者:User
求各位大哥大姐幫我看看這個程式哪點出毛病了
建立一個使用者的類,該類中有“姓名”、“學號”、“年齡”、“聯絡電話”四個私人屬性,要求通過建構函式給屬性“姓名”賦值,其他屬性也通過方法來進行賦值和訪問。列印出使用者“張三”、“200440132”“21”、“63886666”的資訊。
class Message
{
private $name;
private $num;
private $age;
private $tel;

function __construct($name,$num,$age,$tel)
{
$this->name=$name;
$this->num=$num;
$this->age=$age;
$this->tel=$tel;
}
function say()
{
echo "使用者:"$this->name"
學號:"$this->num"
年齡:"$this->age"
聯絡電話:"$this->tel;
}
$p=new Message("張三",200440132,21,63886666);
$p->say();
?>

------解決方案--------------------
PHP code
function say(){echo "使用者:".$this->name."
學號:".$this->num."
年齡:".$this->age."
聯絡電話:".$this->tel;//這裡連號沒用}}//內沒關閉,少大括弧$p=new Message("張三",200440132,21,63886666);
------解決方案--------------------
echo "使用者:".$this->name."
學號:".$this->num."
年齡:".$this->age."
聯絡電話:".$this->tel;

注意串連符
------解決方案--------------------
PHP code
name=$name;$this->num=$num;$this->age=$age;$this->tel=$tel;}function say(){echo "使用者:".$this->name."
學號:".$this->num."
年齡:".$this->age."
聯絡電話:".$this->tel;//變數與字串的串連符用.}}//少寫了一個}$p=new Message("張三",200440132,21,63886666);$p->say();?>
------解決方案--------------------
感謝半天不結貼的
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.