Ask for help? PHP OOP case

Source: Internet
Author: User
Tags php oop
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;
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.