尽管我的代码符合 PHP 语法,但我的代码不起作用。
$x=200;
$y=100;
class Human {
public $numLegs=2;
public $name;
public function __construct($name){
$this->name=$name; // The PHP stops being parsed as PHP from the "->"
}
public function greet(){
print "My name is $name and I am happy!"; // All of this is just written to the screen!
}
}
$foo=new Human("foo");
$bar=new Human("bar");
$foo->greet();
$bar->greet();
echo "The program is done";
为什么它不起作用?这实际上是输出,复制粘贴:
名称=$名称;} public function greet(){ print "我的名字是 {this->$name} 我很高兴!"; } } $foo=new Human("foo"); $bar=new Human("bar"); $foo->问候();$bar->问候();echo "程序完成"; ?>