Ask for help? PHP OOP Example
class animal{
Public $name = "";
Public $color = "";
Public $age = "";
function GetInfo () {return $this->name;}
function SetInfo ($name) {return $this->name;} Compiler prompt Warning
}
$pig =new animal ();
$pig->setinfo (' pig ');
$name = $pig->getinfo ();//Compiler hint Error
Echo $name;
?> PHP
Share to:
------Solution--------------------
$pig =new animal ();
$pig->setinfo (' pig ');//This is the wrong line, your semicolon is the full-width semicolon.
$name = $pig->getinfo ();//Compiler hint Error
Echo $name;
/**
In addition: After the code, the format of it
*/
------Solution--------------------
The previous line is a full-width semicolon?
------Solution--------------------
Class person{
Private $name;
function SetName ($name) {
return $this->name = $name;
}
function GetName () {
return $this->name;
}
}
$p = new Person ();
$p->setname (' Lizhi ');
echo $p->getname ();
?>
------Solution--------------------
Why did you get the error?
is because you have a capital semicolon in line 10th,
Why didn't you export "pig"?
Give it a try
function SetInfo ($name) {return $this->name;} Compiler prompt Warning
Change into
function SetInfo ($name) {$this->name = $name;} The compiler prompts the police
------Solution--------------------
Class animal{
Public $name = "";
Public $color = "";
Public $age = "";
function GetInfo () {
return $this->name;
}
function SetInfo ($name) {
$this->name = $name; This is supposed to be an assignment, you must have copied it wrong.
}
}
$pig =new animal ();
$pig->setinfo (' pig '); It turned out to be full-width;
$name = $pig->getinfo ();
Echo $name;