Home  >  Article  >  Backend Development  >  求大姐帮小弟我看看这个程序哪点出毛病了

求大姐帮小弟我看看这个程序哪点出毛病了

WBOY
WBOYOriginal
2016-06-13 13:48:20826browse

求各位大哥大姐帮我看看这个程序哪点出毛病了
建立一个用户的类,该类中有“姓名”、“学号”、“年龄”、“联系电话”四个私有属性,要求通过构造函数给属性“姓名”赋值,其他属性也通过方法来进行赋值和访问。打印出用户“张三”、“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."<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 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();
?>
<br><font color="#e78608">------解决方案--------------------</font><br>感谢半天不结贴的 <div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn