<?php
class Animal{
public $name;
public $color;
public function __construct($color){
$this->color=$color;
}
function write($name){
echo $this->name=$name." Can write!";
}
function run($name){
echo $this->name=$name." Can run!";
}
}
$dog=new Animal("yellow");
$dog->write("Dog");
echo '<br/>';
$sheep=new Animal("white");
$sheep->run("Sheep");
echo '<br/>';
echo " sheep color is ".$sheep->$color; //这行报错,该怎么调用$color这个属性?
?>
$sheep->color, do not need the $
in front of colorecho " sheep color is ".$sheep->color; //This line is written like this. If $ exists, color will become an undefined variable?