这是关闭php的最后一行的代码有一个我似乎无法找到的错误。该代码适用于我的大学项目。开放的php括号很好但是在第27行似乎是代码本身有错误。
<?php
include_once 'ShapeClass.php';
class Circle extends Shape
{
private $radius;
function __construct($n,$c,$r)
{
parent::__construct($n,$c);
$this->radius = $r;
}
public function area()
{
return ( pi()*$this->radius * $this->radius);
}
public function perimeter()
{
return ( 2 * pi() * $this->radius);
}
public function compareParameters($s)
{
case "Circle":
}
{if ($this->radius > $r->radius)
{
print "<h2>This circle's radius is bigger</h2>";
}
else
{
print "<h2>This circle's radius is not bigger</h2>";
}
break;
}
case "Square":
{if ($this->radius > $s->side)
{
print "<h2>This circle's radius is bigger than the square's side</h2>";
}
else
{
print "<h2>This circle's radius is not bigger than the square's side</h2>" ;
}
break;
}
case "Rectangle":
{if ($this->radius > $w->width)
{
print "<h2>This circle's radius is bigger then the rectangle's width</h2>";
}
else
{
print "<h2>This circle's radius is not bigger than the rectangle's width</h2>" ;
}
break;
}
case "Rectangle":
{if ($this->radius > $h->height)
{
print "<h2>This circle's radius is bigger than the rectangle's height</h2>";
}
else
{
print "<h2>This circle's radius is not bigger than the rectangle's height</h2>";
}
break;
}
case "Triangle":
{if ($this->radius > $b->base)
{
print "<h2>This circle's radius is bigger than the triangle's base</h2>";
}
else
{
print "<h2>This circle's radius is not bigger than the triangle's base</h2>" ;
}
break;
}
case "Triangle":
{if ($this->radius > $ha->height)
{
print "<h2>This circle's radius is bigger than the triangle's height</h2>";
}
else
{
print "<h2>This circles radius is not bigger than the triangle's height</h2>";
}
break;
}
case "Triangle":
{if ($this->radius > $hb->hypotenuse)
{
print "<h2>This circle's radius is bigger than the triangle's hypotenuse</h2>";
}
else
{
print "<h2>This circle's radius is not bigger than the triangle's hypotenuse</h2>" ;
}
break;
}
case "Parallelogram":
{if ($this->radius > $sb->sidebase)
{
print "<h2>This circle's radius is bigger than the parallelogram's base</h2>";
}
else
{
print "<h2>This circle's radius is not bigger than the parallelogram's base</h2>";
}
break;
}
case "Parallelogram":
{if ($this->radius > $sh->sideheight)
{
print "<h2>This circle's radius is bigger than the parallelogram's height</h2>";
}
else
{
print "<h2>This circle's radius is not bigger than the parallelogram's height</h2>";
}
break;
}
?>
答案 0 :(得分:2)
您有case
个案例,但周围没有switch
。
检查http://www.php.net/manual/en/control-structures.switch.php
看起来应该有点像:
switch (...) {
case "..." {
...
break;
}
case "..." {
...
break;
}
case "..." {
...
break;
}
case "..." {
...
break;
}
default: {
...
break;
}
}
{}
/ case
语句中的default
是可选的
default
语句也是可选的。