我在本地主机上运行这段代码。在http://localhost:8000/Polymorphism.php上运行时出现错误。这是php上的一个简单的多态代码。其他代码运行起来很轻松,但是运行这段代码就出错了。
此页面不工作本地主机当前无法处理此请求。HTTP 错误 500
<?php
public interface Shape{
public function calculateArea();
}
public class Circle implements Shape{
private $radius;
public function __construct($r){
$this->radius=$r;
}
public function calculateArea(){
echo 'Area of circle = '.pi()* $this->radius*$this->radius.'<br>';
}
}
class Rectangle implements Shape{
private $height;
private $width;
public function __construct($h,$w){
this->height=$h;
this->width=$w;
}
public function calculateArea(){
echo 'Area of a Rectangle=' .$this->height.$this->width.'<br>';
}
}
$circle= new Circle(5);
$rect= new Rectangle(10,20);
$circle->calculateArea();
$rect->calculateArea();
?>
蓝山帝景