我是PHP 7的新手,我的课上有问题,我和Hapedit合作,这里是源代码
<?php header("Content-type: text/html; charset=ISO-8859-1");
class Personne {
protected $_nom;
protected $_prenom;
protected $_dateNaissance;
protected $_salaire; }
function __getNom($_nom){
return $this->$_nom;
}
function __getPrenom($_prenom){
return $this->$_prenom;
}
function __getdateNaissance($_dateNaissance){
return $this->$_dateNaissance;
}
function __getSalaire($_salaire){
return $this->$_salaire;
}
//setters
function __setNom($nom)
{
$this->_nom = $nom;
}
function __setPrenom($prenom)
{
$this->_prenom = $prenom;
}
function __setdateNaissance($dateNaissance)
{
$this->_dateNaissance = $dateNaissance ;
}
function __setSalaire($salaire)
{
$this->_salaire = $salaire;
}
//méthode pour afficher des informations sur la personne en question
function info(){
echo 'La personne a comme nom ' .$this->_nom . 'et prenom ' . $this-
>_prenom. ' est ne en ' .$this->_dateNaissance. ' et a comme salaire ' .
$this->_salaire;
}
//declaration d’un objet Personne
$_perso = new Personne()
$_perso->setNom('Rossafi');
$_perso->setPrenom('Ahmed');
$_perso->setdateNaissance('1991');
$_perso->setSalaire('5000');
$_perso->info();
?>
我的目标是创建一个Personne类,首先用方法info()显示一个人的所有信息
我有这个错误:
你能帮忙吗?谢谢解析错误:语法错误,意外&#39; $ _ perso&#39; (T_VARIABLE)在第53行的C:\ xampp \ htdocs \ www \ TPPHPObjet1 \ Personne.php
答案 0 :(得分:0)
你错过了一个分号。
//declaration d’un objet Personne
$_perso = new Personne() <---- there should be a semicolon here
$_perso->setNom('Rossafi');
$_perso->setPrenom('Ahmed');
建议你使用像netbeans,phpstorm或zend studio这样的IDE。他们将突出显示这些问题,你将能够看到第53行的内容
此外,您的课程在方法之前结束。这就是我认为你的班级正在努力构建的方式。
class Personne
{
protected $_nom;
protected $_prenom;
protected $_dateNaissance;
protected $_salaire;
function __getNom($_nom)
{
return $this->$_nom;
}
function __getPrenom($_prenom)
{
return $this->$_prenom;
}
function __getdateNaissance($_dateNaissance)
{
return $this->$_dateNaissance;
}
function __getSalaire($_salaire)
{
return $this->$_salaire;
}
//setters
function __setNom($nom)
{
$this->_nom = $nom;
}
function __setPrenom($prenom)
{
$this->_prenom = $prenom;
}
function __setdateNaissance($dateNaissance)
{
$this->_dateNaissance = $dateNaissance;
}
function __setSalaire($salaire)
{
$this->_salaire = $salaire;
}
//méthode pour afficher des informations sur la personne en question
function info()
{
echo 'La personne a comme nom ' . $this->_nom . 'et prenom ' . $this->_prenom . ' est ne en ' . $this->_dateNaissance . ' et a comme salaire ' . $this->_salaire;
}
}
同样,IDE在这里很有用,因为它有助于保持格式化的可读性。