日期:2014-05-17  浏览次数:20502 次

求各位大哥大姐帮我看看这个程序哪点出毛病了
建立一个用户的类,该类中有“姓名”、“学号”、“年龄”、“联系电话”四个私有属性,要求通过构造函数给属性“姓名”赋值,其他属性也通过方法来进行赋值和访问。打印出用户“张三”、“200440132”“21”、“63886666”的信息。
<?php
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"<br>学号:"$this->num"<br>年龄:"$this->age"<br>联系电话:"$this->tel;
}
$p=new Message("张三",200440132,21,63886666);
$p->say();
?>

------解决方案--------------------
PHP code

function say()
{
echo "用户:".$this->name."<br>学号:".$this->num."<br>年龄:".$this->age."<br>联系电话:".$this->tel;//这里连号没用
}
}//内没关闭,少大括号
$p=new Message("张三",200440132,21,63886666);

------解决方案--------------------
echo "用户:".$this->name."<br>学号:".$this->num."<br>年龄:".$this->age."<br>联系电话:".$this->tel;

注意连接符
------解决方案--------------------
PHP code

<?php
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."<br>学号:".$this->num."<br>年龄:".$this->age."<br>联系电话:".$this->tel;//变量与字符串的连接符用.
}
}//少写了一个}
$p=new Message("张三",200440132,21,63886666);
$p->say();
?>

------解决方案--------------------
感谢半天不结贴的