name;} functionsetInfo($name){return$this->name;}//编译器提示警告 } $pig=newanimal(); $pig"/>
PHP头条
热点:

求帮忙?phpoop事例


求帮忙?php oop例子
class animal{
public $name="";
public $color="";
public $age="";
function getInfo(){return $this->name;}
function setInfo($name){return $this->name;}//编译器提示警告
}
$pig=new animal();
$pig->setInfo('猪');
$name=$pig->getInfo();//编译器提示错误
echo $name;


?>
PHP 分享到:
------解决方案--------------------

$pig=new animal();
$pig->setInfo('猪');//是这行错了,你的分号为全角的分号。
$name=$pig->getInfo();//编译器提示错误
echo $name;

/**
另外:以后发代码,格式化了吧
*/

------解决方案--------------------
前一行是全角的分号?
------解决方案--------------------

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();
?>

------解决方案--------------------
为什么会报错, 
是因为你第10行有个大写分号,

为什么没输出“猪”
试试
function setInfo($name){return $this->name;}//编译器提示警告
改成
function setInfo($name){$this->name = $name;}//编译器提示警
------解决方案--------------------
class animal{
  public $name="";
  public $color="";
  public $age="";
  function getInfo(){
    return $this->name;
  }
  function setInfo($name){
    $this->name = $name; //这里应该是赋值,想必你复制错了
  }
}
$pig=new animal();
$pig->setInfo('猪'); //这里原来是全角的;
$name=$pig->getInfo();
echo $name;

www.phpzy.comtrue/phprm/13454.htmlTechArticle求帮忙?phpoop事例 求帮忙?php oop例子 classanimal{ public$name=""; public$color=""; public$age=""; functiongetInfo(){return$this->name;} functionsetInfo($name){return$this->name;}//编译器提示警告 } $pig=newanimal(); $pig...

相关文章

相关频道:

PHP之友评论

今天推荐