求各位大哥大姐帮我看看这个程序哪点出毛病了
建立一个用户的类,该类中有“姓名”、“学号”、“年龄”、“联系电话”四个私有属性,要求通过构造函数给属性“姓名”赋值,其他属性也通过方法来进行赋值和访问。打印出用户“张三”、“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();
?>
------解决方案--------------------
function say()
{
echo "用户:".$this->name."<br>学号:".$this->num."<br>年龄:".$this->age."<br>联系电话:".$this->tel;//这里连号没用
}
}//内没关闭,少大括号
$p=new Message("张三",200440132,21,63886666);
<br><font color="#e78608">------解决方案--------------------</font><br>echo "用户:".$this->name."<br>学号:".$this->num."<br>年龄:".$this->age."<br>联系电话:".$this->tel;<br><br>注意连接符
<br><font color="#e78608">------解决方案--------------------</font><br>
<?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();
?>
<br><font color="#e78608">------解决方案--------------------</font><br>感谢半天不结贴的 <div class="clear"></div>
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号