<?php
class Animal{
public $name;
public $color;
public function __construct($color){
$this->color=$color;
}
function write($name){
echo $this->name= $name ." 可以寫!";
}
function run($name){
echo $this->name=$name." 可以運作! ";
}
}
$dog=new Animal("yellow");
$dog->write("Dog") ;
echo '
';
$sheep=new Animal("white");
$sheep->run("羊" );
#echo '
';
echo "羊的顏色是".$sheep->$color; //這行報錯,該如何呼叫$color這個屬性?
?>
$sheep->color,不要color前面的$
echo " sheep color is ".$sheep->color; //這行這樣寫 $存在的話color就成了未定義的變數?